Jump to content


Photo

Inserting data into multiple tables


  • Please log in to reply
7 replies to this topic

#1 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 08 October 2006 - 10:20 PM

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

Do I do this:
	$sql  = "INSERT INTO `pages` ";
	$sql .= "(this, that) ";
	$sql .= "VALUES ";
	$sql .= "('".$this."', '".$that."')";

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


Thanks in advance.
~ Mutley.

#2 Neptunus Maris

Neptunus Maris
  • Members
  • PipPipPip
  • Advanced Member
  • 192 posts

Posted 08 October 2006 - 10:28 PM

<?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());

?>


#3 Neptunus Maris

Neptunus Maris
  • Members
  • PipPipPip
  • Advanced Member
  • 192 posts

Posted 08 October 2006 - 10:37 PM

No...

like this ..sorry:

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

dont do table1 AND table table2

Neptune

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,016 posts

Posted 08 October 2006 - 10:51 PM

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.../en/insert.html
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 09 October 2006 - 08:26 AM

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.../en/insert.html


Would you like to explain how it can be done?
~ Mutley.

#6 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 09 October 2006 - 02:11 PM

Anyone?  :(
~ Mutley.

#7 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,016 posts

Posted 09 October 2006 - 07:00 PM

You posted 2 options. The manual, at least my copy, indicates it cannot be the second.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#8 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 09 October 2006 - 07:17 PM

Ah, ok, I was hoping for a shorter way without repeating it, thanks though.
~ Mutley.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users