You are here: Re: inserting data into multiple tables at the same time « PHP Language « IT news, forums, messages
Re: inserting data into multiple tables at the same time

Posted by Tyno Gendo on 04/07/07 12:26

ZeldorBlat wrote:
> On Apr 6, 8:45 pm, "Mr. Newt" <lektrikpuke@_yahoo.com> wrote:
>> Hi y'all,
>>
>> I wrote the following:
>>
>> <?php
>> include ("connect.php");
>> $sql = "INSERT INTO advertiser_info_tbl (adv_name) values ('$adv_name')";
>> $sql = "INSERT INTO address_info_tbl (address, apt, city, state, zip) values
>> ('$address',
>>
>> '$apt', '$city', '$state', '$zip')";
>> if (mysql_query($sql, $conn)){
>> echo "record added!";} else {
>>
>> echo "something went wrong";}
>>
>> ?>

the proper statement would be

$sql = "INSERT INTO advertiser_info_tbl (adv_name) values ('$adv_name');";
$sql .= " INSERT INTO address_info_tbl (address, apt, city, state, zip)
values ('$address', '$apt', '$city', '$state', '$zip')";


however, if it won't execute both in one go you could do the following:

$cmds = array();
array_push($cmds, "<sqlstatement1>");
array_push($cmds, "<sqlstatement2>");
foreach($cmds as $sql) {
mysql_query($sql) or die(mysql_error());
}

Obviously replace with real statements and put your error checking in.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация