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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.