Mysql DELETE problem
Posted: Fri Sep 29, 2006 2:07 pm
Hello,
I have a code which should delete user and all it's data. Here's the code:
if() sentence executes successfully, but user is not deleted and ids are not updated. while() sentence doesn't even execute. I have put echo "hello"; in while() to test if it has been executed and echo didn't execute.
Maybe someone sees a problem here?
Any help would be appreciated.
Thanks
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