s_ainley87 Posted March 10, 2008 Share Posted March 10, 2008 Can anybody see the reason as to why my file is not being moved across to the uploads folder and the filename is not going to the table? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Product added redirecting....</title> </head> <body> <?php require_once ('include/mysql_connect.php'); // Connect to the database. if ($_POST[op] != "yes"){ // Check if the form has been submitted. if (!empty($_POST['Prodname'])) { $pn = escape_data($_POST['Prodname']); } else { $pn = FALSE; echo '<p><font color="red">Please enter the product\'s name!</font></p>'; } if (!empty($_POST['Catname'])) { $cn = escape_data($_POST['Catname']); } else { $cn = FALSE; echo '<p><font color="red">Please enter the product\'s category name!</font></p>'; } // Check for an image. if (is_uploaded_file ($_FILES['image']['tmp_name'])) { if (move_uploaded_file($_FILES['image']['tmp_name'], "uploads/{$_FILES['image']['name']}")) { // Move the file over. echo "<sript>window.alert('The file has been uploaded!')</script>"; } else { // Couldn't move the file over. echo '<p><font color="red">The file could not be moved.</font></p>'; $i = FALSE; } $i = $_FILES['image']['name']; } else { $i=FALSE; } // Check for a price. if (is_numeric($_POST['Prodprice'])) { $p = $_POST['Prodprice']; } else { $p = FALSE; echo '<p><font color="red">Please enter the products\'s price!</font></p>'; } // Check for a description (not required). if (!empty($_POST['Proddesc'])) { $d = escape_data($_POST['Proddesc']); } else { $d = '<i>No description available.</i>'; } if(!isset($pn) || !isset($cn) || !isset($d) || !isset($p) ||!isset($i)) { echo "Somthing is not working"; } elseif (isset($pn) || isset($cn) || isset($p) || isset($d) ||isset($i)) { // Add the product to the database. $query = "INSERT INTO product (product_name, category_name, product_price, product_desc, image_name) VALUES ('$pn','$cn', '$p','$d','$i')"; if (mysql_query ($query,$dbc)) { // Worked. echo "<script> window.alert('Product added you will now be sent back to the hub')</script>"; echo "<script type=\"text/javascript\"> window.location = \"adminhub.php\" </script>"; } else { // If the query did not run OK. echo '<p><font color="red">Your submission could not be processed due to a system error.</font></p>'; } } else { // Failed a test. echo '<p><font color="red">Please click <a href =\"products.php\">back</a> and try again.</font></p>'; } } ?> </body> </html>[\code] Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted March 10, 2008 Share Posted March 10, 2008 probably this: if ($_POST[op] != "yes") Quote Link to comment Share on other sites More sharing options...
djpic Posted March 10, 2008 Share Posted March 10, 2008 try this: $query = "INSERT INTO `product` (`product_name`, `category_name`, `product_price`, `product_desc`, `image_name`) VALUES ('$pn','$cn', '$p','$d','$i')"; Quote Link to comment Share on other sites More sharing options...
dotBz Posted March 10, 2008 Share Posted March 10, 2008 I guess if you'd post the form code then it would be much easier to solve.. Quote Link to comment Share on other sites More sharing options...
s_ainley87 Posted March 12, 2008 Author Share Posted March 12, 2008 this is what the form looks like, i am also getting an undefined index on line 29 that is the is_uploaded_file line. echo " please add the category to the database <br/><form method=\"POST\" action=\"addproddatabase.php\"> <div align=\"left\"> <strong>Product Name:</strong><input type=\"text\" name=\"Prodname\"/><br/><br/> <strong>Category Name:</strong><input type=\"text\" name=\"Catname\"/><br/><br/> <strong>Product Price:</strong><input type=\"text\" name=\"Prodprice\" /><br/><br/> <strong>Product Description</strong><textarea name=\"Proddesc\"/></textarea><br/><br/> <strong>Product Image:</strong><input type=\"file\" name=\"image\" /><br/><br/> <input type=\"submit\" name=\"submit\" value=\"Add To Database\" /> </div> </form>"; Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted March 12, 2008 Share Posted March 12, 2008 i suggest that you turn your error_reporting down so undefined index errors are not reported. this can be done in the PHP configuration file (typically php.ini) or in code using error_reporting(): http://us.php.net/error_reporting Quote Link to comment Share on other sites More sharing options...
s_ainley87 Posted March 12, 2008 Author Share Posted March 12, 2008 Ok thanks, that is one problem down, can you see the reason why my file is not going to the database or being moved across to the uploads folder? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 13, 2008 Share Posted March 13, 2008 Your <form tag is incorrect. It needs to contain an enctype parameter to work - http://www.php.net/manual/en/features.file-upload.php Quote Link to comment Share on other sites More sharing options...
s_ainley87 Posted March 13, 2008 Author Share Posted March 13, 2008 Oh my word that isnt even a PHP mistake it is HTML markup how embarrasing, thank you everyone for you help it is now working perfectly , no doubt you will hear from me soon... Simon (Newbie biting off more than he can chew) Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 13, 2008 Share Posted March 13, 2008 BlueSkyIS, the undefined index error means the code is accessing a variable that does not exist and the code will never work. Changing the error reporting to hide the message just means that the code is still accessing a variable that does not exist and will never work, but now you don't even know what the code is doing that is not working. 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.