Insert into Multiple Tables
Greetings to all,
I am trying to insert one record into multiple tables in a mysql db. I have searched the sql manual for the right syntax but nothing I am doing seems to work. Can someone tell me how to accomplish this ??
The record has six fields that are the same and I want that record inserted into five tables. Here is a sample of the code that I am trying to use.....................
<?php
// start session and bring in session variables
session_start();
@$link = mysql_connect(SYSTEM,USERNAME,PASSWORD);
if(!$link)
{
echo "Database seems to be down";
exit;
}
mysql_select_db(DATABASE) or die( "Unable to select database");
$query = "INSERT INTO table1 (field1,field2,field3,field4,field5,field6) VALUES"
. " ('$field1,'$field2','$field3','$field4,'$field5',' $field6')";
$query = "INSERT INTO table2 (field1,field2,field3,field4,field5,field6) VALUES"
. " ('$field1,'$field2','$field3','$field4,'$field5',' $field6')";
$query = "INSERT INTO table3 (field1,field2,field3,field4,field5,field6) VALUES"
. " ('$field1,'$field2','$field3','$field4,'$field5',' $field6')";
$result = @mysql_query($query);
if(!$result)
{
echo mysql_error().'<br>';
echo "Error - Could not insert your data into the database.";
}
mysql_close();
echo"
<html>
Thanks in advance
Bmalex
Barry Alexander
|