yankeesjtj Posted March 13, 2008 Share Posted March 13, 2008 Hello, I'm trying to create a simple form that will allow me to insert records into a data base. There are 3 fields. Date, Customer name and number of purchase orders What i have so far works for the first time. But the insert fails when you try to insert a second set of records Here is my code. Thanks for the help <html> <head> <title>Insert PO's</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <h1 align="center">EDI PO's - Add a record</h1> <?php if(isset($_POST['insert'])) { include 'library/po_config.php'; include 'library/opendb.php'; $curr_date = $_REQUEST["curr_date"]; $custname = $_REQUEST["custname"]; $po_quant = $_REQUEST["po_quant"]; $query = "INSERT INTO purch_orders (date, customer_name, po_quantity) VALUES ('$curr_date', '$custname', '$po_quant')"; mysql_query($query) or die('Error, insert query failed'); $query = "FLUSH PRIVILEGES"; mysql_query($query) or die('Error, insert query failed'); include 'library/closedb.php'; echo "Data Added"; $curr_date = trim('curr_date'); $custname = trim('custname'); $po_quant = trim('po_quant'); echo <<<HERE <br> <form method="post"> <input name="another" type="submit" id="another" value="Insert Another Record"> </form> HERE; } else { ?> <form method="post"> <table align = "center" width="400" border="0" cellspacing="1" cellpadding="2"> <tr> <td width="100">Date (yyyy-mm-dd) : </td> <td><input name="curr_date" type="text" id="curr_date"></td> </tr> <tr> <td width="100">Customer Name</td> <td><select name="custname"> <option value="Wallys Wallets">Wally's Wallets</option> <option value="Franks Fish Farm">Franks Fish Farm</option> <option value="Sals Smoke Shop">Sal's Smoke Shop</option> <option value="Leroys Leather Goods">Leroys Leather Goods</option> <option value="Carls Computers">Carl's Computers</option></td> </tr> <tr> <td width="100">PO Quantity</td> <td><input name="po_quant" type="text" id="po_quant"></td> </tr> <tr> <td width="100"> </td> <td><input name="insert" type="submit" id="add" value="Insert record"></td> </tr> </table> </form> <?php } ?> </body> </html> Jason Link to comment https://forums.phpfreaks.com/topic/95901-inserting-records-phpmysql/ Share on other sites More sharing options...
peranha Posted March 13, 2008 Share Posted March 13, 2008 what type of error are you getting?? Link to comment https://forums.phpfreaks.com/topic/95901-inserting-records-phpmysql/#findComment-490998 Share on other sites More sharing options...
yankeesjtj Posted March 13, 2008 Author Share Posted March 13, 2008 I just get the error that i specified in the code when trying to do the insert. "Error, insert query failed" Link to comment https://forums.phpfreaks.com/topic/95901-inserting-records-phpmysql/#findComment-491017 Share on other sites More sharing options...
rofl90 Posted March 13, 2008 Share Posted March 13, 2008 replace "error, insert query failed with mysql_error() and it will give us a better idea, use that from now on too. Link to comment https://forums.phpfreaks.com/topic/95901-inserting-records-phpmysql/#findComment-491019 Share on other sites More sharing options...
peranha Posted March 13, 2008 Share Posted March 13, 2008 <html> <head> <title>Insert PO's</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <h1 align="center">EDI PO's - Add a record</h1> <?php if(isset($_POST['insert'])) { include 'library/po_config.php'; include 'library/opendb.php'; $curr_date = $_REQUEST["curr_date"]; $custname = $_REQUEST["custname"]; $po_quant = $_REQUEST["po_quant"]; $query = "INSERT INTO purch_orders (date, customer_name, po_quantity) VALUES ('$curr_date', '$custname', '$po_quant')"; mysql_query($query) or die("Error in query: $query. ".mysql_error()); $query = "FLUSH PRIVILEGES"; mysql_query($query) or die("Error in query: $query. ".mysql_error()); include 'library/closedb.php'; echo "Data Added"; $curr_date = trim('curr_date'); $custname = trim('custname'); $po_quant = trim('po_quant'); echo <<<HERE <br> <form method="post"> <input name="another" type="submit" id="another" value="Insert Another Record"> </form> HERE; } else { ?> <form method="post"> <table align = "center" width="400" border="0" cellspacing="1" cellpadding="2"> <tr> <td width="100">Date (yyyy-mm-dd) : </td> <td><input name="curr_date" type="text" id="curr_date"></td> </tr> <tr> <td width="100">Customer Name</td> <td><select name="custname"> <option value="Wallys Wallets">Wally's Wallets</option> <option value="Franks Fish Farm">Franks Fish Farm</option> <option value="Sals Smoke Shop">Sal's Smoke Shop</option> <option value="Leroys Leather Goods">Leroys Leather Goods</option> <option value="Carls Computers">Carl's Computers</option></td> </tr> <tr> <td width="100">PO Quantity</td> <td><input name="po_quant" type="text" id="po_quant"></td> </tr> <tr> <td width="100"> </td> <td><input name="insert" type="submit" id="add" value="Insert record"></td> </tr> </table> </form> <?php } ?> </body> </html> Try that and tell us what they error says. I changed the error to add they mysql error Link to comment https://forums.phpfreaks.com/topic/95901-inserting-records-phpmysql/#findComment-491021 Share on other sites More sharing options...
yankeesjtj Posted March 13, 2008 Author Share Posted March 13, 2008 replace "error, insert query failed with mysql_error() and it will give us a better idea, use that from now on too. Error in query: INSERT INTO purch_orders (date, customer_name, po_quantity) VALUES ('2008-02-24', 'Franks Fish Farm', '34'). Duplicate entry '2008-02-24' for key 1 it seems the only way right now it doesn't give me this duplicat error message is if i clear my browser cache before entering the 2nd set... Link to comment https://forums.phpfreaks.com/topic/95901-inserting-records-phpmysql/#findComment-491028 Share on other sites More sharing options...
peranha Posted March 13, 2008 Share Posted March 13, 2008 Is the date field in the database set to unique, meaning only 1 can have that amount. that is what it seems like to me Link to comment https://forums.phpfreaks.com/topic/95901-inserting-records-phpmysql/#findComment-491030 Share on other sites More sharing options...
yankeesjtj Posted March 13, 2008 Author Share Posted March 13, 2008 Is the date field in the database set to unique, meaning only 1 can have that amount. that is what it seems like to me Thats exactly what it was. Thanks for all the help! Link to comment https://forums.phpfreaks.com/topic/95901-inserting-records-phpmysql/#findComment-491034 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.