arunpatal Posted November 7, 2012 Share Posted November 7, 2012 (edited) I am trying to add 2nd image but its not working. fileField upload the image and name it $pid.jpg which is id (auto_increment) i added new field into database call img1, now i want to upload another image which will be named as img1 input field. Please check <?php // Parse the form data and add inventory item to the system if (isset($_POST['product_name'])) { $product_name = mysql_real_escape_string($_POST['product_name']); $price = mysql_real_escape_string($_POST['price']); $img1 = mysql_real_escape_string($_POST['img1']); $category = mysql_real_escape_string($_POST['category']); $subcategory = mysql_real_escape_string($_POST['subcategory']); $details = mysql_real_escape_string($_POST['details']); // See if that product name is an identical match to another product in the system $sql = mysql_query("SELECT id FROM products WHERE product_name='$product_name' LIMIT 1"); $productMatch = mysql_num_rows($sql); // count the output amount if ($productMatch > 0) { echo 'Sorry you tried to place a duplicate "Product Name" into the system, <a href="inventory_list.php">click here</a>'; exit(); } // Add this product into the database now $sql = mysql_query("INSERT INTO products (product_name, price, img1, details, category, subcategory, date_added) VALUES('$product_name','$price','$img1','$details','$category','$subcategory',now())") or die (mysql_error()); $pid = mysql_insert_id(); // Place image in the folder $newname = "$pid.jpg"; move_uploaded_file( $_FILES['fileField']['tmp_name'], "../inventory_images/$newname"); header("location: inventory_list.php"); exit(); $img1 = "$img1"; move_uploaded_file( $_FILES['fileField1']['tmp_name'], "../inventory_images/$img1"); header("location: inventory_list.php"); exit(); } ?> OK guys.... Now its working I had to take off exit(); Edited November 7, 2012 by arunpatal Quote Link to comment https://forums.phpfreaks.com/topic/270425-adding-image/ Share on other sites More sharing options...
AyKay47 Posted November 7, 2012 Share Posted November 7, 2012 Your use of the exit statement here is incorrect. You should be using the correct if { }else { } conditional instead: if ($productMatch > 0) { 'true block' }else{ 'false block' } Also, check to make sure the file was actually uploaded before using header(); if(move_uploaded_file( $_FILES['fileField1']['tmp_name'], "../inventory_images/$img1")) { header("location: inventory_list.php"); }else { 'error handler' } Quote Link to comment https://forums.phpfreaks.com/topic/270425-adding-image/#findComment-1390900 Share on other sites More sharing options...
arunpatal Posted November 7, 2012 Author Share Posted November 7, 2012 (edited) Thanks Edited November 7, 2012 by arunpatal Quote Link to comment https://forums.phpfreaks.com/topic/270425-adding-image/#findComment-1390913 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.