Jump to content

Inserting data into multiple tables


Mutley

Recommended Posts

I've done a form but I want certain areas (fields) to insert into different tables.

Do I do this:
[code=php:0]
$sql  = "INSERT INTO `pages` ";
$sql .= "(this, that) ";
$sql .= "VALUES ";
$sql .= "('".$this."', '".$that."')";
[/code]

...and repeat it above each field I want it to go into a different table or can I do something like this:
[code=php:0]
$sql  = "INSERT INTO `table1` AND `table2` AND `table3` ";
$sql .= "(*) ";
$sql .= "VALUES ";
$sql .= "('".$this."', '".$that."')";
[/code]


Thanks in advance.
Link to comment
Share on other sites

[sup]<?php
//do some variable work
$this = $_POST['this'];
$that = $_POST['that'];

$query = "INSERT INTO $table VALUES(' ', '$this')";
$result = mysql_query($query, $connect) or die(mysql_error());

//create a second query clause
$query = "INSERT INTO $table2 VALUES(' ' , '$that')";
$result = mysql_query($query, $connect) or die(mysql_error());

?>[/sup]
Link to comment
Share on other sites

[quote author=Barand link=topic=110906.msg449021#msg449021 date=1160347884]
Well you must have a different manual from me because I can't find an INSERT syntax that allows multiple tables

http://dev.mysql.com/doc/refman/5.0/en/insert.html
[/quote]

Would you like to explain how it can be done?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.