Forum Moderators: coopster
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();
}
}