Results 1 to 1 of 1

Thread: MySQL insert multiple records from FORM

  1. #1
    Join Date
    Nov 2005
    Location
    Austin TX,US
    Posts
    71
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default MySQL insert multiple records from FORM

    I have simple form with mutiples of 2 fields: status1 / name1,status2 / name2...
    Code:
    <form method="post" action="test1_edit.php">
    <input type='checkbox' name='status[]' value='active'>Status1
    <input name="name[]" type="text" />Name1<br />
    <input type='checkbox' name='status[]' value='active'>Status2 
    <input name="name[]" type="text" />Name2<br />
    <input name="submit" type="submit" /><br />
    </form>
    The test1_edit.php file is as below. If I only INSERT $status, the form is working fine, but I don't how to INSERT both $status and $name in FOREACH.
    Code:
    $status=$_POST['status'];
    $name=$_POST['name'];
    
    foreach ($status as $status ){
    mysql_query ("INSERT INTO test (status)
    VALUES('$status')",$connection);
    //mysql_query ("INSERT INTO test (status, name))  
    VALUES('$status','$name')",$connection);// This doesn't work.
      if (mysql_affected_rows()==1){
        continue;
      } else {
        echo "<p class='register'> Something went wrong!</p>";
        break;
      }
    } 
    header("Location: test1.php");
    ?>
    Thanks for help! This is really urgent for tomorrow the assingment is due.
    Last edited by mtran; 06-05-2006 at 11:01 PM.

Bookmarks

Posting Permissions

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