Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Need help collecting data from a form (loop) that changes

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Need help collecting data from a form (loop) that changes

Postby PWN r00t » Thu Jul 24, 2003 12:34 pm

the code below takes user input (a 1-2 digit number) and loops to create the form and its variables but im having a hard time with the code that will take these Posted variables and put them in a MySQL database

my guess is that some how i need to stuff these into an array upon submit yet maybe there is a better way...

Code: Select all
 

print "<form action='modules.php?op=modload&name=Registration&file=index&eventname=$samename' method='POST'>
           <hr><table>";
  for ($i=1; $i<$j+1; $i++) {

    print "
  <tr>
    <td>First&$i</td><td><input type='text' size='13' name='first$i' value=''><td>
        Last&$i</td><td><input type='text' size='13' name='last$i' value=''><td>
        Email&$i</td><td><input type='text' size='15' name='email$i' value=''><td>
    </td>
  </tr>
";
  }
  print "</table><hr><table><tr>";
  print "<td><input type='submit' name='groupofnames' value='Enter Group and Continue'></td></tr></table>";
  print "</form>";
}



Thanks in advance
User avatar
PWN r00t
New php-forum User
New php-forum User
 
Posts: 3
Joined: Thu Jul 24, 2003 12:13 pm

Postby swirlee » Thu Jul 24, 2003 7:59 pm

Yes, you need to put these values into an array. To make PHP put the contents a bunch of HTML form fields into an array, you must give them all the same name, followed by []. Like so:

Code: Select all
<form action="script.php" method="POST">
   <?
      for($i = 0; $ < 3; $i++) {
         echo 'Input ' . $i . ":<br />\n";
         echo '<input type="text" name="myarray[]">', "<br />\n";
      }
   ?>
</form>


This should generate a form with three text fields with labels "Input 1", "Input 2", and "Input 3", and when the form is submitted, all of their data will be lumped into the array $_POST['myarray'].
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron