Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 6th, 2006, 12:45 PM
Registered User
 
Join Date: Feb 2006
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.....................

<?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





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





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