Jump to content

storing and retreiving multiple text fields


brownd

Recommended Posts

I am trying to have my users store multiple text field values at once, here is a copy of my form code

 

  <form name="form1" method="post" action="test2.php">

    <table width="100%" border="1">

      <tr>

        <td>Class</td>

        <td>Title</td>

        <td>Comments</td>

      </tr>

      <tr>

        <td><label>

          <input type="text" name="class" id="class" />

        </label></td>

        <td><label>

          <input type="text" name="book" id="book" />

        </label></td>

        <td><label>

          <input type="text" name="comments" id="comments" />

        </label></td>

      </tr>

        <tr>

        <td><label>

          <input type="text" name="class" id="class" />

        </label></td>

        <td><label>

          <input type="text" name="book" id="book" />

        </label></td>

        <td><label>

          <input type="text" name="comments" id="comments" />

        </label></td>

      </tr>

        <tr>

        <td><label>

          <input type="text" name="class" id="class" />

        </label></td>

        <td><label>

          <input type="text" name="book" id="book" />

        </label></td>

        <td><label>

          <input type="text" name="comments" id="comments" />

        </label></td>

      </tr>

        <tr>

        <td><label>

          <input type="text" name="class" id="class" />

        </label></td>

        <td><label>

          <input type="text" name="book" id="book" />

        </label></td>

        <td><label>

          <input type="text" name="comments" id="comments" />

        </label></td>

      </tr>

        <tr>

        <td><label>

          <input type="text" name="class" id="class" />

        </label></td>

        <td><label>

          <input type="text" name="book" id="book" />

        </label></td>

        <td><label>

          <input type="text" name="comments" id="comments" />

        </label></td>

      </tr>

        <tr>

        <td><label>

          <input type="text" name="class" id="class" />

        </label></td>

        <td><label>

          <input type="text" name="book" id="book" />

        </label></td>

        <td><label>

          <input type="text" name="comments" id="comments" />

        </label></td>

      </tr>

        <tr>

        <td><label>

          <input type="text" name="class" id="class" />

        </label></td>

        <td><label>

          <input type="text" name="book" id="book" />

        </label></td>

        <td><label>

          <input type="text" name="comments" id="comments" />

        </label></td>

      </tr>

        <tr>

        <td><label>

          <input type="text" name="class" id="class" />

        </label></td>

        <td><label>

          <input type="text" name="book" id="book" />

        </label></td>

        <td><label>

          <input type="text" name="comments" id="comments" />

        </label></td>

      </tr>

        <tr>

        <td><label>

          <input type="text" name="class" id="class" />

        </label></td>

        <td><label>

          <input type="text" name="book" id="book" />

        </label></td>

        <td><label>

          <input type="text" name="comments" id="comments" />

        </label></td>

      </tr>

        <tr>

        <td><label>

          <input type="text" name="class" id="class" />

        </label></td>

        <td><label>

          <input type="text" name="book" id="book" />

        </label></td>

        <td><label>

          <input type="text" name="comments" id="comments" />

        </label></td>

      </tr>

      </table>

          <input type="submit" name="submit" id="submit" value="Submit" />

  </form>

 

As you can see three fields are repeated multiple times, how do I store these values in mysql and later retreive them.

Well, first of all, you need unique names for your fields. An easy way would be with a for loop like this:

 

<?php
for ($i=0;$i<10;$++){ ?>
      <tr>
        <td><label>
          <input type="text" name="class[<?=$i?>]" id="class<?=$i?>" />
        </label></td>
        <td><label>
          <input type="text" name="book[<?=$i?>]" id="book<?=$i?>" />
        </label></td>
        <td><label>
          <input type="text" name="comments[<?=$i?>]" id="comments<?=$i?>" />
        </label></td>
      </tr>
<?php }
?>

 

Then your names are in an array of that input field and your ID's are all unique.

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.