Jump to content

[SOLVED] DELETE a user


cdog5000

Recommended Posts

[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]

Link to comment
https://forums.phpfreaks.com/topic/112349-solved-delete-a-user/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/112349-solved-delete-a-user/#findComment-576825
Share on other sites

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!

Link to comment
https://forums.phpfreaks.com/topic/112349-solved-delete-a-user/#findComment-576828
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.