tags:

views:

40

answers:

1

I'm having an issue when I loop through form input text fields. I am trying to loop through multiple text fields labeled 'number' and it's only submitting the very last number field instead of all 'number' fields. Can anyone see what I'm doing wrong here??

    for ($i = 0; $i < count($_POST['number']); $i++) {
       $sql='INSERT INTO orders (custNum,contractNum,equipId,prodNum)
              VALUES ('
          . "'" . mysql_real_escape_string($_SESSION['custNum']) . "', "
       . "'" . mysql_real_escape_string($_POST['contractNum']) . "', "
        . "'" . mysql_real_escape_string($_POST['equipId']) . "', "
          . "'" . mysql_real_escape_string($_POST['number'][$i]) . "'"


          . ')';
    }


<?php
$i=0;
while ($i < $num) {

$p1=mysql_result($paper_result,$i,"tp");
$p2=mysql_result($paper_result,$i,"prodNum");
$p3=mysql_result($paper_result,$i,"paperDesc");

?>

  <tr>
    <td><select name="quant[]">
     <option value="0">None</option>
      <option value="2">2</option>
      <option value="2">4</option>
      <option value="2">6</option>
      <option value="2">8</option>
      <option value="2">10</option>
      <option value="2">12</option>
      <option value="2">14</option>
      <option value="2">16</option>
      <option value="2">18</option>
      <option value="2">20</option>
    </select></td>
    <td><?php echo $p1; ?></td>
    <td><input type="text" name="number[]" value="<?php echo addslashes($p2); ?>">    </td>
    <td><?php echo $p3; ?></td>
  </tr>
  <?php
$i++;
}
?>
A: 

You never call mysql_query() to actually perform the insert. You need to call this at the end of the for loop (inside the loop).

tandu
Wow, I spent over 5 hours on this and left out something so simple. Thank you very much tandu!!!
cam