-1

It display the result. but when I'm updating it doesnt work.

my multiple table results (working).

               <table>
              <tr>
                 <?php
        $result = $db->prepare("SELECT * FROM famcomp WHERE app_id='". mysql_real_escape_string($app_id) ."'");
        $result->execute();
        for($i=0; $row = $result->fetch(); $i++){
          $app_id1 = $row['app_id'];
          $fullname = $row['fullname'];
          $fage = $row['fage'];
          $frel = $row['frel'];
          $fcivil = $row['fcivil'];
          $fedu = $row['fedu'];
          $foccup = $row['foccup'];
          $finco = $row['finco'];
      ?>
                <td><input type="hidden" name="app_id[]" value="<?php echo $app_id1 ?>" /></td>
                <td><input type="text" name="fullname[]" value="<?php echo $fullname ?>" class="input" /></td>
                <td><input type="text" name="fage[]" value="<?php echo $fage ?>" class="input" /></td>
                <td><input type="text" name="frel[]" value="<?php echo $frel?>" class="input" /></td>
                <td><input type="text" name="fcivil[]" value="<?php echo $fcivil?>" class="input" /></td>
                <td><input type="text" name="fedu[]" value="<?php echo $fedu ?>" class="input" /></td>
                <td><input type="text" name="foccup[]" value="<?php echo $foccup ?>" class="input" /></td>
                <td><input type="text" name="finco[]" value="<?php echo $row['finco']; ?>" class="input" /></td>
            </tr>    
            <?php
                }
            ?>
<br></table>

Here's my approach the result is:

Notice:

  • undefined all index [0][1]
  • Undefined index: fullname[0],etc fullname[1]
$fullname=$_POST['fullname'];
    $N = count($fullname); //to get the total row of fullname
    for($i=0; $i < $N; $i++)
    mysql_query("UPDATE famcomp SET 
         fullname = '".$_POST["fullname[$i]"]."', fage = '".$_POST["fage[$i]"]."',
         frel = '".$_POST["frel[$i]"]."', fcivil = '".$_POST["fcivil[$i]"]."', 
    fedu = '".$_POST["fedu[$i]"]."', foccup = '".$_POST["foccup[$i]"]."',
         finco = '".$_POST["finco[$i]"]."'
         WHERE `app_id` = '".$_POST["app_id[$i]"]."'") 
    or die(mysql_error());
Insane Skull
  • 9,220
  • 9
  • 44
  • 63
kim de castro
  • 299
  • 6
  • 19

1 Answers1

0

In your update query, replace every

$_POST["fullname[$i]"], $_POST["fage[$i]"]...

and so on, with

$_POST["fullname"][$i], $_POST["fage"][$i]...
macl
  • 975
  • 9
  • 15