insert multiple records into mysql from one form

Discussion in 'PHP' started by tradingbasics, May 17, 2007.

  1. #1
    I have a form which displays multiple records each record has a check box in it, what I want to do is when submit button clicked it should insert selected records into mysql.
    I can do single insert but cannot think of how to get this done.

    Thanks
     
    tradingbasics, May 17, 2007 IP
  2. dzysyak

    dzysyak Peon

    Messages:
    43
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can use something like this:

    
    <form>
    <input type="text" name="records[1]"/>
    <input type="text" name="records[2]"/>
    <input type="text" name="records[3]"/>
    </form>
    
    HTML:
    
    foreach($_REQUEST['records'] as $record ){
      mysql_query("....");
    }
    
    PHP:
     
    dzysyak, May 17, 2007 IP
  3. tradingbasics

    tradingbasics Member

    Messages:
    84
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #3
    Thanks for quick reply
    but what I am trying to do, have a select option when that is selected that record should be inserted.
     
    tradingbasics, May 18, 2007 IP
  4. Arson

    Arson Well-Known Member

    Messages:
    622
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    120
    #4
    
    
    if($_POST['record1']==1)
    {
    insert the stuff
    }
    if($_POST['record2']==1)
    {
    insert the stuff
    }
    if($_POST['record3']==1)
    {
    insert the stuff
    }
    
    Code (markup):
    just have if statements m8
     
    Arson, May 18, 2007 IP