Bravat Posted July 19, 2011 Share Posted July 19, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/242342-update-probmel/ Share on other sites More sharing options...
Nodral Posted July 19, 2011 Share Posted July 19, 2011 Try asking your question in an understandable way? What are you trying to acheive? What errors are you getting? What would the desired result be? Quote Link to comment https://forums.phpfreaks.com/topic/242342-update-probmel/#findComment-1244659 Share on other sites More sharing options...
AyKay47 Posted July 19, 2011 Share Posted July 19, 2011 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]"); Quote Link to comment https://forums.phpfreaks.com/topic/242342-update-probmel/#findComment-1244664 Share on other sites More sharing options...
Bravat Posted July 19, 2011 Author Share Posted July 19, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/242342-update-probmel/#findComment-1244681 Share on other sites More sharing options...
AyKay47 Posted July 19, 2011 Share Posted July 19, 2011 refer to my post Quote Link to comment https://forums.phpfreaks.com/topic/242342-update-probmel/#findComment-1244687 Share on other sites More sharing options...
Bravat Posted July 19, 2011 Author Share Posted July 19, 2011 Ooops, my bad . AyKay47 it is working, but I forgot to tell you. Thank you for helping me Quote Link to comment https://forums.phpfreaks.com/topic/242342-update-probmel/#findComment-1244691 Share on other sites More sharing options...
AyKay47 Posted July 19, 2011 Share Posted July 19, 2011 Ooops, my bad . AyKay47 it is working, but I forgot to tell you. Thank you for helping me just wanted to make sure that you didn't miss it somehow... Quote Link to comment https://forums.phpfreaks.com/topic/242342-update-probmel/#findComment-1244694 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.