Re: Solution
| From: | tedd | Date: | Tue, 13 Apr 2010 16:07:27 +0000 |
| Subject: | Re: Solution | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-304036@lists.php.net to get a copy of this message | ||
At 6:04 PM -0400 4/12/10, Gary wrote:
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. GaryGary : It not only looks redundant, but why two tables? Why not "customers" or "users" or "subscribers" like so: include(opendb.php); $query="INSERT INTO users (first_name, last_name, street, town, state, zip) VALUES('$first_name', '$last_name', $street', '$town', '$state', '$zip')"; $result=mysqli_query($dbc, $query) or die('Error querying database.'); include(closedb.php); I don't see any reason to separate the attributes of the person into two different tables. Why do that? Cheers, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com