Jump to content

Archived

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

Mutley

Inserting data into multiple tables

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.

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
No...

like this ..sorry:

INSERT INTO table1, table2, table3, VALUES(' ' , '$this', '$that')"; 

dont do table1 AND table table2

Neptune

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites
You posted 2 options. The manual, at least my copy, indicates it cannot be the second.

Share this post


Link to post
Share on other sites
Ah, ok, I was hoping for a shorter way without repeating it, thanks though.

Share this post


Link to post
Share on other sites

×

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.