Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jul 2006
    Posts
    168
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Create a query to Insert Data

    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

  • #2
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    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.

  • #3
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    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.

  • #4
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    oops thanks GJay, my php is a bit rusty.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •