Jump to content

UPDATE probmel


Bravat

Recommended Posts

I have this block of code:

    if(isset ($_POST['submit']))
    {
        $productName = mysql_real_escape_string($_POST['productName']);
        $productPrice = mysql_real_escape_string($_POST['productPrice']);
        $producteCagegory = mysql_real_escape_string($_POST['productCategory']);
        $productSubcategory = mysql_real_escape_string($_POST['productSubcategory']);
        $productDetails = mysql_real_escape_string($_POST['productDetails']);
        $productImage = $_FILES['productImage']['name'];       
               
        $sql = mysql_query("UPDATE products SET product_name = '$productName', ");
            if($productImage != ""){
        $sql .= ("  image = '$productImage' " ); 
                }
        $sql .=  ( " , price = '$productPrice', description = '$productDetails', category_id = '$producteCagegory', subcategory_id = '$productSubcategory' 
                    WHERE id_product = '$_POST[idProduct]' ")
                            or die(mysql_error());
        if(!empty($productImage))
        {
        move_uploaded_file($_FILES["productImage"]["tmp_name"],
        IMG_UPLOAD . $_FILES["productImage"]["name"]);
        }
        redirect_to("inventory_edit.php?pid=$_POST[idProduct]");           
    }

 

Idea is that if no new image is selected, query does not update image field. What am I doing wrong, and how to do this?

Link to comment
https://forums.phpfreaks.com/topic/242342-update-probmel/
Share on other sites

try this

 

        if(!empty($productImage))
        {
        $sql = mysql_query("UPDATE products SET product_name = '$productName', image = '$productImage', price = '$productPrice', description = '$productDetails', category_id = '$producteCagegory', subcategory_id = '$productSubcategory' 
                    WHERE id_product = '{$_POST[idProduct]}'")
                            or die(mysql_error());
        move_uploaded_file($_FILES["productImage"]["tmp_name"],
        IMG_UPLOAD . $_FILES["productImage"]["name"]);
        }else{
             $sql = mysql_query("UPDATE products SET product_name = '$productName' ") or die(mysql_error());
        }
        redirect_to("inventory_edit.php?pid=$_POST[idProduct]"); 

Link to comment
https://forums.phpfreaks.com/topic/242342-update-probmel/#findComment-1244664
Share on other sites

Nodral I want to be able to update table products when new images is not selected. If I write query this way:

$sql = mysql_query("UPDATE products SET product_name = '$productName', image = '$productImage', price = '$productPrice', description = '$productDetails', category_id = '$producteCagegory', subcategory_id = '$productSubcategory' 
                    WHERE id_product = '{$_POST[idProduct]}'")

then table is updated and new value for image, if nothing is selected, is NULL (works fine when new image is selected).

There is no error, simply nothing happens.

Link to comment
https://forums.phpfreaks.com/topic/242342-update-probmel/#findComment-1244681
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.