cardoso Posted March 9, 2003 Share Posted March 9, 2003 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 Quote Link to comment Share on other sites More sharing options...
kippi Posted March 26, 2008 Share Posted March 26, 2008 hi Nelson Did you ever find away to do this? this is what i am looking for, Many Thanks Quote Link to comment Share on other sites More sharing options...
fenway Posted March 26, 2008 Share Posted March 26, 2008 "multiple records with the same field name" == what does this mean? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted March 26, 2008 Share Posted March 26, 2008 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 } ?> Quote Link to comment Share on other sites More sharing options...
aschk Posted March 27, 2008 Share Posted March 27, 2008 If you have PDO you can use prepared statements to help MySQL with this. And you only have to change the bind variables on each loop. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.