Mutley Posted October 8, 2006 Share Posted October 8, 2006 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 More sharing options...
Neptunus Maris Posted October 8, 2006 Share Posted October 8, 2006 [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 https://forums.phpfreaks.com/topic/23380-inserting-data-into-multiple-tables/#findComment-106007 Share on other sites More sharing options...
Neptunus Maris Posted October 8, 2006 Share Posted October 8, 2006 No...like this ..sorry:INSERT INTO table1, table2, table3, VALUES(' ' , '$this', '$that')"; dont do table1 AND table table2Neptune Link to comment https://forums.phpfreaks.com/topic/23380-inserting-data-into-multiple-tables/#findComment-106009 Share on other sites More sharing options...
Barand Posted October 8, 2006 Share Posted October 8, 2006 Well you must have a different manual from me because I can't find an INSERT syntax that allows multiple tableshttp://dev.mysql.com/doc/refman/5.0/en/insert.html Link to comment https://forums.phpfreaks.com/topic/23380-inserting-data-into-multiple-tables/#findComment-106013 Share on other sites More sharing options...
Mutley Posted October 9, 2006 Author Share Posted October 9, 2006 [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 tableshttp://dev.mysql.com/doc/refman/5.0/en/insert.html[/quote]Would you like to explain how it can be done? Link to comment https://forums.phpfreaks.com/topic/23380-inserting-data-into-multiple-tables/#findComment-106138 Share on other sites More sharing options...
Mutley Posted October 9, 2006 Author Share Posted October 9, 2006 Anyone? :( Link to comment https://forums.phpfreaks.com/topic/23380-inserting-data-into-multiple-tables/#findComment-106245 Share on other sites More sharing options...
Barand Posted October 9, 2006 Share Posted October 9, 2006 You posted 2 options. The manual, at least my copy, indicates it cannot be the second. Link to comment https://forums.phpfreaks.com/topic/23380-inserting-data-into-multiple-tables/#findComment-106435 Share on other sites More sharing options...
Mutley Posted October 9, 2006 Author Share Posted October 9, 2006 Ah, ok, I was hoping for a shorter way without repeating it, thanks though. Link to comment https://forums.phpfreaks.com/topic/23380-inserting-data-into-multiple-tables/#findComment-106441 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.