Forum Moderators: coopster

Message Too Old, No Replies

Middle table insert doesn't work

         

Ann_G

4:48 pm on Oct 21, 2004 (gmt 0)

10+ Year Member



I can't figure out why the data from my middle table won't insert into MYSQL. I'm probably overlooking something very obvious. If any one has the time to take a look at my script I'll be very grateful.

I have 3 tables. Using the script below, the 1st table and 3rd table receive data without any problem, but nothing goes into the 2nd table except the id and the LAST_INSERT_ID ().

The 2nd table is structured exactly like the 3rd table, with the first field set as the auto indexing key and the second field as the foreign key.

All I want is for the data to go into three different tables when users fill out a form.

if (isset($_POST['submit'])){
$query = "INSERT INTO table1 (first_name, last_name) VALUES (
'".mysql_escape_string($_POST['first_name'])."',
'".mysql_escape_string($_POST['last_name'])."', )";

$result = @mysql_query ($query);
$incident_id = mysql_insert_id();

$query = "INSERT INTO table2(table1_id, witn_fname, witn_lname, witn_street, witn_city, witn_phone)
VALUES (LAST_INSERT_ID (),
'".mysql_escape_string($_POST['witn_fname'])."', '".mysql_escape_string($_POST['witn_lname'])."',
)";

$result = @mysql_query ($query);
$incident_id = mysql_insert_id();

$query = "INSERT INTO table3(table1_id, call_made, call_time) VALUES (LAST_INSERT_ID (),
'".mysql_escape_string($_POST['call_made'])."', '".mysql_escape_string($_POST['call_time'])."',)";

if(!mysql_query($query) ) {
print "Error with query: \"$query\"<br />".mysql_error();
}
}

Ann_G

5:13 pm on Oct 21, 2004 (gmt 0)

10+ Year Member



Please disregard my post about the middle table not working. I should have investigated yet a little further. I had a colon in my form field and that I didn't have in the corresponding script.