Jump to content

Loop is messing-up id's


Suchy

Recommended Posts

<php foreach($crew as $person) { ?>
      Name:<input name="person" type="text" id="person" value="<? print($person['name']); ?>" /><br>
      ID: <?php print($person['id']); ?><br>
   	  <input name="id" type="hidden" value="<?php print($person['id']); ?>" /><br>
      <input name="change" id="change" type="submit"  value="change_info" /><br>
      <input name="del" id="del" type="submit"  value="del_info" />
                   <br><br>												
<php }  ?>	

<?php
if(in("change")){    
            $id = mysql_real_escape_string ($_POST['id']);
  	$person = mysql_real_escape_string($_POST['person']);
 echo ($person . " ---- " . $id);
 $query = "UPDATE workers SET  person = '$person' WHERE id = '$id' ";
 $result = mysql_query($query);
} 

if(in("del")){  
  $id = mysql_real_escape_string ($_POST['id']);
  $query = "DELETE FROM workers WHERE id = '$id'";
  $result = mysql_query($query);
} 

?>

 

Because of the loop that prints all the workers when I try to change any name or delete any worker (by pressing on the button next to that name) only the last record gets changed or deleted.

 

How can I fix this ?

 

Link to comment
https://forums.phpfreaks.com/topic/107389-loop-is-messing-up-ids/
Share on other sites

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.