|
Posted by Mr. Newt on 04/07/07 13:36
"Tyno Gendo" <user@example.com> wrote in message
news:46178E14.8030002@example.com...
> 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.
Thanks for all the answers. Everyone has been very helpful.
I may be making my life harder than it needs to be. I'm writing a db for a
friend and have never done anything this big before. So, trying to be
fancy, I decided to try normalizing the data first. I decided to separate
the advertiser table from the address table, because I might add addresses
(like mailing addresses of customers) to the address table. So, that's why
I want to be able to access/write data in more than one table at a time. I
figured it can't be that hard, because every php example I've seen has
multiple tables and data must be related.
Anything I can read or direction in this area would be appreciated.
Thank you.
Robert
Navigation:
[Reply to this message]
|