For those that were looking to see a solution, this is what I have come up
with. It was pointed out on another board (MySQL) that inserting multiple
in one script is probably prohibited because of security reasons.
What I did was open the connection, insert into the table, close the
connection, close the php script, then start over again. This is the code:
$dbc=mysqli_connect('localhost','root','','test')or die('Error connecting to
MySQL server');
$query="INSERT INTO name(fname, lname)"."VALUES('$fname','$lname')";
$result=mysqli_query($dbc, $query)
or die('Error querying database.');
mysqli_close($dbc);
?>
<?php
$dbc=mysqli_connect('localhost','root','','test')or die('Error connecting to
MySQL server');
$query="INSERT INTO address (street, town, state,
zip)"."VALUES('$street','$town','$state','$zip')";
$result=mysqli_query($dbc, $query)
or die('Error querying database.');
mysqli_close($dbc);
?>
It seems a little redundant for PHP, however it seems to work.
Thank you to everyone that responded. If by the way someone sees an issue
with this solution, I would love to read it.
Gary
""Gary"" <[email protected]> wrote in message
news:[email protected]...
> Tommy
>
> Thanks for your reply. The code you had read I was trying to concatonate
> the insert commands without the semicolon at the end....I had also tried
> using the semicolons on each line...same result.
>
> I am reading about the mysqli_multi_query now, so far I am not getting the
> results. Interestingly, it lead me to the mysqli_store_result(), however
> it said it returned a false result on the insert command.
>
> Thank you for your reply...
>
> Gary
>
>
> ""Tommy Pham"" <[email protected]> wrote in message
> news:013601cad93e$e0bca6a0$a235f3...@com...
> Hi Gary,
>
>> -----Original Message-----
>> From: Gary [mailto:[email protected]]
>> Sent: Saturday, April 10, 2010 2:28 PM
>> To: [email protected]
>> Subject: [PHP] Inserting into multiple tables
>>
>> I am experimenting with multiple tables, it is only a test that is my
>> local
>> machine only. This is the current code, which does not work , I have
>> tried
>> to concatonate the insert statements. I have tried multiple $query
>> variables, but it is just overwriting itself (only the last one gets
>> inserted). I also tried writing the $query as an array, which got me an
>> error message (saying it was expecting a string and I offered an
>> array).
>>
>> Someone point me in the right direction?
>>
>> Gary
>>
>> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
>> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>> <html xmlns="http://www.w3.org/1999/xhtml">
>> <head>
>> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
>> <title>Untitled Document</title>
>> </head>
>>
>> <body>
>>
>> <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
>>
>> <label>First Name </label> <input name="fname" type="text" /><br /><br
>> />
>> <label>Last Name </label><input name="lname" type="text" /><br /><br />
>> <label>Street Address </label><input name="street" type="text" /><br
>> /><br
>> />
>> <label>Town </label><input name="town" type="text" /><br /><br />
>> <label>State </label><input name="state" type="text" /><br /><br />
>> <label>Zip Code</label><input name="zip" type="text" /><br /><br />
>> <label>Telephone</label><input name="phone" type="text" /><br /><br />
>> <label>Fax</label><input name="fax" type="text" /><br /><br />
>> <label>E-Mail</label><input name="email" type="text" /><br /><br />
>> <label>Comments</label><br /><textarea name="comments" cols="100"
>> rows="15"></textarea><br /><br />
>>
>> <input name="submit" type="submit" value="submit" />
>> </form>
>>
>> <?php
>>
>> $fname=($_POST['fname']);
>> $lname=($_POST['lname']);
>> $street=($_POST['street']);
>> $town=($_POST['town']);
>> $state=($_POST['state']);
>> $zip=($_POST['zip']);
>> $phone=($_POST['phone']);
>> $fax=($_POST['fax']);
>> $email=($_POST['email']);
>> $comments=($_POST['comments']);
>> $REMOTE_ADDR=$_SERVER['REMOTE_ADDR'];
>>
>> $dbc=mysqli_connect('localhost','root','','test');
>> $query="INSERT INTO address (street, town, state,
>> zip)"."VALUES('$street','$town','$state','$zip')".
>> "INSERT INTO comments(comments)"."VALUES('$comments')".
>> "INSERT INTO
>> contact(phone,fax,email)"."VALUES('$phone','$fax','$email')".
>> "INSERT INTO name (fname, lname)"."VALUES('$fname','$lname')";
>>
>> $result = mysqli_query($dbc, $query)
>> or die('Error querying database.');
>>
>
> I see 2 problems:
>
> 1) your sql statements are not separated by semicolon <- very important
> when executing multiquery
> 2) you could try mysql_multi_query
> http://www.php.net/manual/en/mysqli.multi-query.php
>
> Regards,
> Tommy
>
>> mysqli_close($dbc);
>>
>> ?>
>> </body>
>> </html>
>>
>>
>>
>> __________ Information from ESET Smart Security, version of virus
>> signature database 5016 (20100410) __________
>>
>> The message was checked by ESET Smart Security.
>>
>> http://www.eset.com
>>
>>
>>
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus
> signature database 5017 (20100411) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus
> signature database 5017 (20100411) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>
>
> __________ Information from ESET Smart Security, version of virus
> signature database 5021 (20100412) __________
>
> The message was checked by ESET Smart Security.
>
> http://www.eset.com
>
>
>
__________ Information from ESET Smart Security, version of virus signature
database 5023 (20100412) __________
The message was checked by ESET Smart Security.
http://www.eset.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php