Re: Solution
| From: | Gary | Date: | Tue, 13 Apr 2010 16:26:37 +0000 |
| Subject: | Re: Solution | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-304043@lists.php.net to get a copy of this message | ||
Tedd
I had four tables. name, (fname, lname) address(street, town, state, zip),
contact(phone, fax, email), comments (comments).
It was done this way because it is strictly a learning exercise. I had
never created a DB with multiple tables, so I wanted to be able to contruct
one using foreign keys, and be able to insert and retrieve from it.
But the experiment continues. For whatever reason, scripts to query a DB
that I have used for years are not working. I am thinking it has something
to do with that I switched engines to innodb.
So the lesson continues.
Gary
"tedd" <tedd.sperling@gmail.com> wrote in message
news:p06240804c7ea44eb9789@[192.168.1.102]...
> 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.
>>
>>Gary
>
> Gary :
>
> 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
>
> __________ Information from ESET Smart Security, version of virus
> signature database 5025 (20100413) __________
>
> The message was checked by ESET Smart Security.
>
> http://www.eset.com
>
>
>
__________ Information from ESET Smart Security, version of virus signature database 5025 (20100413)
__________
The message was checked by ESET Smart Security.
http://www.eset.com