Diether Posted December 4, 2012 Share Posted December 4, 2012 (edited) Hi guys Good day, my problem is this. everytime i click the "add this item now" button. the data is not insert in my database. is there anyway to isolate my problem in codes? there is also no error appears. thats why i cant figured out whats the problem. please help me guys. thanks in advance here is my form screenshot: my codes: <?php // This block grabs the whole list for viewing $product_list = ""; $sql = mysql_query("SELECT * FROM product ORDER BY date_added DESC"); $productCount = mysql_num_rows($sql); // count the output amount if ($productCount > 0) { while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $product_name = $row["name"]; $price = $row["price"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); $product_list .= "Product ID: $id - <strong>$product_name</strong> - $$price - <em>Added $date_added</em> <a href='inventory_edit.php?pid=$id'>edit</a> • <a href='inventory_list.php?deleteid=$id'>delete</a><br />"; } } else { $product_list = "You have no products listed in your store yet"; } // Parse the form data and add inventory item to the system if (isset($_POST['name'])) { $product_name = mysql_real_escape_string($_POST['name']); $price = mysql_real_escape_string($_POST['price']); //$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 product WHERE 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 product (name, price, details,date_added) VALUES('$product_name','$price',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(); } ?> <!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"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <head><title>Inventory</title></head> <style type="text/css"> <!-- .style1 {font-size: 10px} --> </style></head> <link rel="stylesheet" href="../stylesheet/style.css" type="text/css" media="screen" /> <body> <div align = "center"id="wrapper"> <div id="content"><br/> <div align = "right" style="margin-right:140px;"> <a href="inventory_list.php#inventory_form">+ Add new inventory item</a> </div> <div align= "left" style = "margin-left:140px;"> <h2>Inventory List</h2> <?php echo $product_list; ?> </div> <div align="left"> <blockquote> <blockquote> <blockquote> <blockquote> <p id="inventory_form" name="inventory_form"><a name = "inventory_form" id="inventory_form"></a> </p> </blockquote> </blockquote> </blockquote> </blockquote> </div> <h3>Add New Inventory Item Form</h3> <form id="my_form" name="my_form" method="post" action="inventory_list.php" enctype="multipart/form-data"> <table width="633" height="248" border="1"> <tr> <td width="156"><label>Product Name:</label> </td> <td width="425"><input type="text" name="product_name" id="product_name" /></td> </tr> <tr> <td><label>Product Price:</label></td> <td>$ <input type="text" name="price" id="price" /></td> </tr> <tr> <td height="45">Product Details:</td> <td> <textarea name="details" id="details"></textarea></td> </tr> <tr> <td>Product Image:</td> <td> <input type="file" name="fileField" id="fileField" /> </td> </tr> <tr> <td> </td> <td> <input type="submit" name="submit" id="submit" value="Add this item now" /></td> </tr> </table> </form> <p> </p> <p> </p> <p> </p> <p><br/> </p> </div> </div> </body> </html> <?php include("../includes/footer.php"); ?> Edited December 4, 2012 by Diether Quote Link to comment https://forums.phpfreaks.com/topic/271587-help-problem-with-inserting-data/ Share on other sites More sharing options...
Christian F. Posted December 4, 2012 Share Posted December 4, 2012 Hint: Where's the input field named "name"? Quote Link to comment https://forums.phpfreaks.com/topic/271587-help-problem-with-inserting-data/#findComment-1397451 Share on other sites More sharing options...
NomadicJosh Posted December 4, 2012 Share Posted December 4, 2012 (edited) I second what Christian F. states above. Also, I would like to add something about your insert query: $sql = mysql_query("INSERT INTO product (name, price, details, date_added) VALUES('$product_name','$price',now())"); You've listed four fields after 'product', but you only list three variables after 'Values'. Edited December 4, 2012 by parkerj Quote Link to comment https://forums.phpfreaks.com/topic/271587-help-problem-with-inserting-data/#findComment-1397529 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.