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
https://forums.phpfreaks.com/topic/23380-inserting-data-into-multiple-tables/
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]
[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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.