...

View Full Version : Create a query to Insert Data



kenwvs
09-04-2006, 03:13 AM
I have a form that includes a bunch of fields to fill out. I have the query working for most of them, but right now am stuck on getting one area to work.

I have 7 fields where you can input a parts number (name=number[]) and then another 7 fields where you input the description of the part (name=description[]).

I want to put them into a database that has one column for the number, one column for the description and then a primary key and foreign key to eventually join them to the main workorder table.

I am not sure how to make a query that will INSERT them into the DB columns, one row for each number/description combination, and check to make sure there is data in the rows. There may not always be 7 part number/descriptions in the form fields and I don't want a bunch of empty rows in the DB table.

Any help on making this happen.

Thanks

Ken

guelphdad
09-04-2006, 03:41 PM
if you are using PHP you would use ISSET to see if the field has been set to a value, otherwise ignore the field. if all three items in the row are not set then you wouldn't end up inserting that row.

GJay
09-04-2006, 08:03 PM
you'd probably want !empty rather than isset, as an empty string will be 'set' when tested...but yeah, loop over the array in PHP (or whatever) and do an insert for each.

guelphdad
09-04-2006, 08:54 PM
oops thanks GJay, my php is a bit rusty.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum