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

Link to comment
Share on other sites

  • 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
  }
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.