Jump to content

Inserting dynamicaly created rows into mysql?


cardoso

Recommended Posts

Hi,

 

I have a form where I dynamically create fields using PHP and a while loop. Basically, I display:

swimmer name Field | Pace Field | Time Field | Date Field

swimmer name Field | Pace Field | Time Field | Date Field

swimmer name Field | Pace Field | Time Field | Date Field etc...

 

one line for every swimmer in the table.

 

I want to insert all of these records into a mysql table when they hit submit. I know how to do this with one record but I\'m new and have never done this with multiple records with the same field name.

 

Can you please help me out and please provide a small example as I have a feeling I have to use arrays... and I\'m new at this.

 

 

Thank you so much!

Nelson

  • 5 years later...

your form elements should get [] added to them like so:

 

<input type="text" name="name[]" /><input type="text" name="pace[]" /><input type="text" name="time[]" /><input type="text" name="date[]" /><br>
<input type="text" name="name[]" /><input type="text" name="pace[]" /><input type="text" name="time[]" /><input type="text" name="date[]" /><br>
<input type="text" name="name[]" /><input type="text" name="pace[]" /><input type="text" name="time[]" /><input type="text" name="date[]" /><br>
<input type="text" name="name[]" /><input type="text" name="pace[]" /><input type="text" name="time[]" /><input type="text" name="date[]" /><br>

 

then in your PHP:

 

<?php
  for($n=0;$n < count($_POST['name']);$n++){
    $name = $_POST['name'][$n];
    $pace = $_POST['pace'][$n];
    $time = $_POST['time'][$n];
    $date = $_POST['date'][$n];
    //Now do you insert
  }
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.