Jump to content

query2 should insert based on last insert id in query1


turpentyne

Recommended Posts

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';

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.