I have a code which should delete user and all it's data. Here's the code:
Code: Select all
if ($action == 'delete') {
$id = $_GET['id'];
$sql = "DELETE * FROM `users` WHERE id = $id";
$result = mysql_query($sql);
$sql = "SELECT id FROM users ORDER BY id DESC LIMIT 1"; // this is to get the highest id
$result = mysql_query($sql);
$re = mysql_fetch_array($result);
$max = $re['id']; // highest id
$id += 1;
while($id <= $max){ // this updates all user's ids bellow the deleted user
$sql = "UPDATE users SET id = id - 1 WHERE id = $id";
$result = mysql_query($sql);
$id += 1;
} // while
}Maybe someone sees a problem here?
Any help would be appreciated.
Thanks