mardi 5 janvier 2021

set conditions in php for editng table in database

I set these conditions in php for uploading images and for editing table in database. $show_edit actually is the url of image in table that uploaded.I can upload image but whene I upload only one image foreaxmple I uploade image2 the image2 field in table will be updated but other fields about image1 and image3 become empty.I tried diffrent ways,I used elseif or even I used loop but I coudnt solve this problem yet. .Thank you for your help. these codes about uploading image and after break;codes about edit function.

case 'edit':
    $id = $_GET['id'];
    $show_parent = $product->Show_parent_product();
    $show_base = $product->Show_base_product();
    $show_edit = $product->Show_product_edit($id);
    if (isset($_POST['btn'])) {
        $data = $_POST['frm'];
        //Start Upload Image Product
        $exts = array('image/png', 'image/jpeg');

        if ($_FILES['image1']) {
            $first_image_edit = $product->uploader_images("../public/uploaded_images/", $data['title'], "image1", $exts);
        }else{
            $first_image_edit = $show_edit['image1'];
        }
        if ($_FILES['image2']) {
            $second_image_edit = $product->uploader_images("../public/uploaded_images/", $data['title'], "image2", $exts);
        }else{
            $second_image_edit = $show_edit['image2'];
        }
        if ($_FILES['image3']) {
            $third_image_edit = $product->uploader_images("../public/uploaded_images/", $data['title'], "image3", $exts);
        }else{
            $third_image_edit = $show_edit['image3'];
        }
        //End Upload Image Product
        $product->Edit_product($id, $data,$first_image_edit,$second_image_edit,$third_image_edit);
        //header("location:index.php?c=product&a=edit&id=$show_edit[id]&product=updated");
    }

    break;




public function Edit_product($id,$data,$first_image_edit,$second_image_edit,$third_image_edit){


    $fields=array_keys($data);
    foreach ($fields as $val){
        $txt[]=$val."='".$data[$val]."'";
    }
    $query=implode(",",$txt);
    $sql=$this->connect->prepare("update product_tbl set image1='$first_image_edit',image2='$second_image_edit',image3='$third_image_edit',".$query." where id='$id'");
    var_dump($sql);
    $sql->execute();
}

Aucun commentaire:

Enregistrer un commentaire