Thank you for your well thought out response.
I did not include any anti-injection functions because this was an
experiment for multiple tables, it is on my machine only.
Since these are php scripts, I dont think anyone will mind (not to mention
this board always provides great answers).,
However I think I may have answered my question about the importance of
normalization of tables. I have written a number of databases used on
various web sites, however, they all are used as a collection of data from
Most of the information about mutilple tables deals with the retreval of
data from, not inserting into, meaning they are more used for known data
inserted by the database owner/administrator to be retrieved by queries into
Am I on the right track?
Again, thank you for your replies.
"Adam Richardson" <simples...@gmail.com> wrote in message
> On Sat, Apr 10, 2010 at 7:56 PM, Gary <g...@paulgdesigns.com> wrote:
>> Thanks for your reply, but I think I am totally confused. Not so much by
>> your answer (although I admit I did not get it to work yet), but by the
>> entire multiple table issue. Several books I use talk about the
>> of using multiple tables, yet are thin on the insert issue. Searching
>> web I have read several answers saying you simply cant insert into
>> tables at once.
>> So if multiple tables is such an important issue, why is there no insert
>> solution. What am I missing?
>> "Adam Richardson" <simples...@gmail.com> wrote in message
>>> On Sat, Apr 10, 2010 at 5:27 PM, Gary <gwp...@ptd.net> wrote:
>>> I am experimenting with multiple tables, it is only a test that is my
>>>> machine only. This is the current code, which does not work , I have
>>>> 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
>>>> Someone point me in the right direction?
>>>> I'm not aware of any multi-table insert syntax:
>>> You'd have to perform 4 separate mysql_query() calls to accomplish what
>>> you're looking for (one for each insert.)
>>> That said, I'd recommend using a transaction so you make sure all of the
>>> inserts succeed or fail together (it would cause issues down the road if
>>> table insert worked and another failed.) Additionally, I'd recommend
>>> prepared statements to avoid SQL injection (I'd mention validation your
>>> data, too ;)
>>> See the tutorial below:
>>> Nephtali: PHP web framework that functions beautifully
>>> __________ Information from ESET NOD32 Antivirus, version of virus
>>> signature database 5016 (20100410) __________
>>> The message was checked by ESET NOD32 Antivirus.
>> __________ Information from ESET NOD32 Antivirus, version of virus
>> signature database 5016 (20100410) __________
>> The message was checked by ESET NOD32 Antivirus.
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
> Hi Gary,
> The benefit of breaking up the data across multiple tables (when the data
> has certain characteristics) is that you can better protect the integrity
> the data through what's called normalization (
> If you have a database in which you'd like to store employees, perhaps one
> of the fields would be the address of the office building they work in.
> Now, you could build the database so it uses one table to store all of the
> data (first name, last name, office building address, etc.) Up front,
> might seem reasonable, but what happens when employees in office building
> move to a new location? In this table, you'd have to carefully replace
> address for each employee with the new address.
> How will you find all of the employees that need to have the address
> updated? Did you type in the address exactly the same (down to even the
> spaces in the words) in every row? It's very possible that this scheme
> eventually lead to errors.
> However, the other approach would be to break this database up into 2
> tables, one for the core employee data (first name, last name, etc.), and
> one table for office building locations because there is redundancy. Now
> the employee table wouldn't actually contain the actual office building
> address, it would contain a reference to the row in the office building
> address table. When you want to change the address for an office
> you merely change one row and it impacts every employee avoiding the
> potential pitfalls of the first example using 1 table for everything.
> That said, just because this scheme better protects the integrity of the
> data doesn't mean it's easier. Sometimes your inserts will have to impact
> multiple tables, and they will all have to be performed separately.
> However, after inserting OR updating your data, you will be able to sleep
> at night knowing that your data properly reflects the intentions of the
> changes you've made.
> Now, looking at your example, I notice very little redundancy. That is,
> unless someone can submit comments again later on, all of the fields would
> be unique to the particular individual submitting the form. This data
> easily be stored in the same table (just include an id field as a primary
> key), and there shouldn't be any issues.
> I'd recommend reading a book like that below that works through PHP AND
> MySQL in a very nice manner:
> I probably won't provide much follow-up on MySQL database normalization in
> follow-up emails so-as not to upset others on the list as this list
> on PHP, but I hope I helped you get started on the right track and avoid
> becoming discouraged. It takes some time to get it to "click", but once
> does, DB development will be just as fun and easy as PHP ;)
> Nephtali: PHP web framework that functions beautifully
> __________ Information from ESET Smart Security, version of virus
> signature database 5016 (20100410) __________
> The message was checked by ESET Smart Security.
__________ Information from ESET Smart Security, version of virus signature
database 5016 (20100410) __________
The message was checked by ESET Smart Security.
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php