I'm trying to create a form that enters information into two tables. In the table1 I'd like to enter the contact's information. In the table2 enter their comment.
Then I want to update the table2 with the id that was generated with the insert into table1. The form is breaking on the insert into table2. I tested out the SQL and it worked for the second table insert.
$sql="INSERT INTO table1 (firstname, email, phone)
VALUES ('".$Name."','".$Email."', '".$Phone."')";
$sql.="INSERT INTO table2 (notes_comments, created_date)
VALUES ('".$comments."','".$date."')";
$sql.="UPDATE table2, table1
SET table2.notes_quote_id = table1.id
WHERE table1 = '".$date."'
AND table2.notes_comments = '".$comments."'
AND table2.created_date = table1.created_date";
What am I doing wrong?
BELOW is the corrected statement that now works for me:
$sql="INSERT INTO table1 (firstname, email, phone)
VALUES ('".$yourName."','".$yourEmail."', '".$yourPhone."');";
$sql.="INSERT INTO table2 (notes_comments, created_date)
VALUES ('".$comments."','".$datefix."');";
$sql.="UPDATE table2
INNER JOIN table1
ON table2.created_date = table1.created_date
SET table2.notes_quote_id = table1.id
WHERE table1.id = (SELECT MAX(id) FROM table1);";