Suchy Posted May 27, 2008 Share Posted May 27, 2008 <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 More sharing options...
The Little Guy Posted May 27, 2008 Share Posted May 27, 2008 probably because name="person" isn't unique in the form. Link to comment https://forums.phpfreaks.com/topic/107389-loop-is-messing-up-ids/#findComment-550581 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.