Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 6th, 2006, 12:45 PM
Registered User
Join Date: Feb 2006
Location: Dallas, Texas, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to bmalex1
Default 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.....................


// start session and bring in session variables

@$link = mysql_connect(SYSTEM,USERNAME,PASSWORD);
echo "Database seems to be down";
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);
  echo mysql_error().'<br>';
  echo "Error - Could not insert your data into the database.";

Thanks in advance


Barry Alexander
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Command to insert data in multiple tables? dstein4d Access VBA 3 November 18th, 2008 09:16 AM
How do I INSERT INTO multiple tables using array? aspiretech PHP Databases 0 December 10th, 2005 12:53 AM
Importing Multiple files in Multiple tables Versi Suomi Access 6 June 1st, 2005 08:47 AM
Multiple Recordsets from Multiple Tables TSEROOGY Classic ASP Databases 2 December 28th, 2004 12:45 PM
Insert into different Tables cs9896 SQL Language 2 September 16th, 2003 03:52 AM

All times are GMT -4. The time now is 12:19 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.