cdog5000 Posted June 28, 2008 Share Posted June 28, 2008 [code][code] ok... i need help.. i have this form that'll try to delete a user from Login.php /* Get data. */ $sql = "SELECT * FROM Login ORDER BY id"; $result = mysql_query($sql); echo " <TABLE BORDER=4 CELLPADDING=2 CELLSPACING=2 WIDTH=100%>"; while ($row = mysql_fetch_assoc($result)) { $userrow = $row['userid']; echo " <TR> <TD>" . $row['username'] . "</TD> <TD>" . $row['id'] . "</TD> <TD> <form method = post action = ../deleteUser.php > <input type=hidden name=hiddenid2 value=$userrow /> <input type = submit name=submitdelete value=delete /> </form></TD> </TR> "; } echo "</TABLE>"; here's deleteUser.php <?php mysql_connect(nah nah nah) or die(mysql_error ()); mysql_select_db(kokokoko) or die(mysql_error()); mysql_query("DELETE FROM Login WHERE id='$_POST[hiddenid2]'"); header('location: ../addUser.php'); ?> but when i press the button in the first form it delete's all users!!!!! i need help[/code][/code] Quote Link to comment https://forums.phpfreaks.com/topic/112349-solved-delete-a-user/ Share on other sites More sharing options...
CMC Posted June 28, 2008 Share Posted June 28, 2008 It is doing that because you are selecting ALL the users $sql = "SELECT * FROM Login ORDER BY id"; and displaying all of the users (including hidden id's) in the table. You can either limit the users returned (LIMIT #) or re-arrange your script. I would add a checkbox beside each username and have the checkbox's value as the id. Then you set the script up that it will only delete the users that have been checked. Make sense? Quote Link to comment https://forums.phpfreaks.com/topic/112349-solved-delete-a-user/#findComment-576825 Share on other sites More sharing options...
cdog5000 Posted June 28, 2008 Author Share Posted June 28, 2008 [sOLVED] i found that my $userrow = $row['userid']; was supposed to be $userrow = $row['id']; Quote Link to comment https://forums.phpfreaks.com/topic/112349-solved-delete-a-user/#findComment-576827 Share on other sites More sharing options...
cdog5000 Posted June 28, 2008 Author Share Posted June 28, 2008 It is doing that because you are selecting ALL the users $sql = "SELECT * FROM Login ORDER BY id"; and displaying all of the users (including hidden id's) in the table. You can either limit the users returned (LIMIT #) or re-arrange your script. I would add a checkbox beside each username and have the checkbox's value as the id. Then you set the script up that it will only delete the users that have been checked. Make sense? well first off... i wanna show all users... and have a delete button for each! Quote Link to comment https://forums.phpfreaks.com/topic/112349-solved-delete-a-user/#findComment-576828 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.