turpentyne Posted February 21, 2012 Share Posted February 21, 2012 I'm missing something here. I have a form, and when the submit is pressed, the relevant post data inserts into table one, then I want the last insert id to insert along with other form data into a second table. The first table's still inserting fine, but I can't get that second one to do anything. It leapfrogs over the query and doesn't give an error. EDIT: I forgot to add an error: I get: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'usage, why VALUES ('14', '', '123', '','1234', '', '')' at line 1 query:INSERT INTO tbl_donar (donar_fname, donar_name, donar_address, donar_address2, donar_city, donar_state, donar_zip, donar_email, donar_phone, donar_fax, donar_company) VALUES ('test 14', 'asdfa', 'asdf', 'adf','asdf', '', '', '', '123', '', '') if (empty($errors)) { require_once ('dbconnectionfile.php'); $query = "INSERT INTO tbl_donar (donar_fname, donar_name, donar_address, donar_address2, donar_city, donar_state, donar_zip, donar_email, donar_phone, donar_fax, donar_company) VALUES ('$description12', '$sn', '$description4', '$cne','$description5', '$description6', '$description7', '$description8', '$description9', '$description10', '$description11')"; $result = @mysql_query ($query); if ($result) { $who_donated=mysql_insert_id(); $query2 = "INSERT INTO tbl_donation (donor_id, donor_expyear, donor_cvv, donor_cardtype, donor_authorization, amount, usage, why) VALUES ('$who_donated', '$donate2', '$donate3', '$donate4','$donate5', '$donate6', '$donate7')"; $result2 = @mysql_query ($query2); if ($result2) {echo "Info was added to both tables! yay!";} echo "table one filled. Table two was not."; echo $who_donated; //header ("Location: http://www.twigzy.com/add_plant.php?var1=$plant_id"); exit(); } else { echo 'system error. No donation added'; Link to comment https://forums.phpfreaks.com/topic/257432-query2-should-insert-based-on-last-insert-id-in-query1/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 21, 2012 Share Posted February 21, 2012 Your second query is failing because usage is a reserved mysql keyword. You can use mysql_error to get php/mysql to tell you why a query is failing and at what point in the query mysql found a problem. Link to comment https://forums.phpfreaks.com/topic/257432-query2-should-insert-based-on-last-insert-id-in-query1/#findComment-1319423 Share on other sites More sharing options...
jcbones Posted February 21, 2012 Share Posted February 21, 2012 That means to surround usage in backticks to specify it as a column name. `usage`, or change the name to something else. Link to comment https://forums.phpfreaks.com/topic/257432-query2-should-insert-based-on-last-insert-id-in-query1/#findComment-1319428 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.