brucegregory Posted May 14, 2012 Share Posted May 14, 2012 This is probably some obvious error I have made, but I cannot figure it out. I have made a few pages and now I am debugging them. My first page is called insert_purchase_order.php; on this page a person will enter some data in fields and hit the insert button. Then, the data is passed to another page, but when I try to insert into mysql it does not give me any errors, but I have no new rows either. The code for my 2nd page: <?php session_start(); $action=$_GET[action]; if ($action==insert){ $randid=$_POST['randid']; $vendor=$_POST["vendor"]; $purchase_order_date=$_POST["purchase_order_date"]; $ship=$_POST["ship"]; $fob=$_POST["fob"]; $terms=$_POST["terms"]; $buyer=$_POST["buyer"]; $freight=$_POST["freight"]; $req_date=$_POST["req_date"]; $confirming_to=$_POST["confirming_to"]; $remarks=$_POST["remarks"]; $tax=$_POST["tax"]; $con = mysql_connect("localhost","root","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("main", $con); mysql_query("INSERT INTO purchase_order (randid, vendor, purchase_order, ship, fob, terms, buyer, freight, req_date, confirming_to, remarks, tax) VALUES ($randid, $vendor,$purchase_order_date,$ship, $fob, $terms, $buyer, $freight, $req_date, $confirming_to, $remarks, $tax)"); mysql_close($con); echo 'Data Accepted...'; echo '<br/>'; echo 'P.O. Inserted Successfully'; }else{ echo 'Error... Please Contact Bruce.'; echo 'Bruce, no data was passed from the insert_purchase_order.php page.'; } ?> <a href="http://localhost/insert_purchase_order_items.php?po= <?php echo $randid; ?>">Insert Purchase Order Items</a> I have permissions and everything. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/262533-cant-insert-items-into-mysql/ Share on other sites More sharing options...
Pikachu2000 Posted May 14, 2012 Share Posted May 14, 2012 You aren't checking for errors being returned from the database. The query is failing because string values need to be enclosed in quotes in the query string. Quote Link to comment https://forums.phpfreaks.com/topic/262533-cant-insert-items-into-mysql/#findComment-1345464 Share on other sites More sharing options...
brucegregory Posted May 14, 2012 Author Share Posted May 14, 2012 You aren't checking for errors being returned from the database. The query is failing because string values need to be enclosed in quotes in the query string. So I need to add ' ' to each one in the VALUE query? Quote Link to comment https://forums.phpfreaks.com/topic/262533-cant-insert-items-into-mysql/#findComment-1345466 Share on other sites More sharing options...
brucegregory Posted May 14, 2012 Author Share Posted May 14, 2012 one of the values needs to be purchase_order_date, not purchase_order. Quote Link to comment https://forums.phpfreaks.com/topic/262533-cant-insert-items-into-mysql/#findComment-1345467 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.