davey_b_ Posted April 28, 2008 Share Posted April 28, 2008 i have a basic upload image script but when no image is selected it still puts "productsmall_1209413585" in the database. if the image is true then "productsmall_1209412913ne_grp1.gif" is entered and all works fine... what have i done wrong?? <?php //////////// Image config ////////////// $picsmall = $_FILES['userfile'][0]; $picbig = $_FILES['userfile'][1]; $picsmallname = $_FILES['userfile']['name'][0]; $picbigname = $_FILES['userfile']['name'][1]; $picsmalltype = $_FILES['userfile']['type'][0]; $picbigtype = $_FILES['userfile']['type'][1]; $final_image_big = "productlarge_".time().$picbigname; $final_image_small = "productsmall_".time().$picsmallname; $picsmalldest = $prodimagedir . $picsmallname; $picbigdest = $prodimagedir . $picbigname; if (!is_readable($prodimagedir) || !is_writable($prodimagedir) || !is_executable($prodimagedir)) { $error = true; $message .= " * Change the permission of 'products' folder in the root to 777 <br>"; } if ($picsmalltype != "") { if (!isValidWebImageType($picsmalltype)) { $message .= " * Invalid product picture (small)! Upload an image (jpg/gif/png)" . "<br>"; $error = true; } else { if (file_exists($picsmalldest)) { $message .= " * Product picture (small) with the same name exists! Please rename the product picture (small) and upload! " . "<br>"; $error = true; } } } if ($picbigtype != "") { if (!isValidWebImageType($picbigtype)) { $message .= " * Invalid product picture (big)! Upload an image (jpg/gif/png)" . "<br>"; $error = true; } else { if (file_exists($picbigdest)) { $message .= " * Product picture (big) with the same name exists! Please rename the product picture (big) and upload! " . "<br>"; $error = true; } } } PS. I need to time stamp it in case 2 images with the same name get uploaded. Quote Link to comment Share on other sites More sharing options...
mrdamien Posted April 29, 2008 Share Posted April 29, 2008 Posting the section of your code relating to the database insert would be helpful. Quote Link to comment Share on other sites More sharing options...
davey_b_ Posted April 29, 2008 Author Share Posted April 29, 2008 of course... here's the rest plus the sql update <?php if ($message != "") { // error $message = "<br>Please correct the following errors to continue!<br>" . $message; } else { // no error so insert user details if($picsmallname != ""){ move_uploaded_file($_FILES['userfile']['tmp_name'][0], "../products/".$final_image_small); if($_FILES['userfile']['tmp_name'][0] != "") { chmod("../products/$final_image_small", 0777); generateThumbNail("../products/".$final_image_small,"../products/".$final_image_small,150,150); } } if($picbigname != ""){ move_uploaded_file($_FILES['userfile']['tmp_name'][1], "../products/".$final_image_big); if($_FILES['userfile']['tmp_name'][1] != "") { chmod("../products/$final_image_big", 0777); generateThumbNail("../products/".$final_image_big,"../products/".$final_image_big,400,400); } } $sql = "UPDATE ".$tableprefix."products SET product_name = '".addslashes($txtProductName)."', product_code = '".addslashes($txtProductCode)."', product_description = '".addslashes($txtDescription)."', product_short_desc = '".addslashes($txtShort_desc)."', product_price = '".addslashes($txtPrice)."', product_postage = '".addslashes($txtPostage)."', product_addpostage = '".addslashes($txtAddpostage)."', product_youtube = '".addslashes($txtYoutube)."', product_category = '".addslashes($ddlCategory)."', product_tags = '".addslashes($txtTags)."', "; if($picsmallname != ""){ $sql .= "product_image_small = '".addslashes($final_image_small)."',"; } if($picbigname != ""){ $sql .= "product_image_big = '".addslashes($final_image_big)."',"; } Quote Link to comment Share on other sites More sharing options...
davey_b_ Posted April 29, 2008 Author Share Posted April 29, 2008 bump Quote Link to comment Share on other sites More sharing options...
mrdamien Posted April 30, 2008 Share Posted April 30, 2008 It seems like your just forgetting to prevent the query from executing unless $picsmallname != "" && $picbigname != "" Its hard to say without actually seeing where the update is called. Quote Link to comment 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.