0

Hello,
I am trying to get the MySQL id field to auto update itself when an item is deleted. However the below doesnt work.

When a user searches by name, then I need to grab the id of that name before I delete it and minus 1.

$name = $_POST['name'];

if ($_POST['id'].value.length == 0){
	$id = false;}
else{
$id = $_POST['id'];}

$lowcase = strtolower($name);
$ucname = ucwords($lowcase);

if ($id = false){
$result = mysql_query("SELECT id FROM tuck WHERE item='$ucname'");
$id = mysql_fetch_array($result);}

mysql_query("DELETE FROM tuck WHERE item='$ucname'");
mysql_query("UPDATE tuck SET id=id-1 WHERE id >'$id'");

echo "Item '" . $ucname . "' deleted";

It did work briefly when i had

mysql_query("UPDATE tuck SET id=id-1 WHERE id >= '$id'");

but then that also -1 from the numbers below it as well.

Thanks for any help offered.

Edited by ben.marks: n/a

2
Contributors
1
Reply
4
Views
6 Years
Discussion Span
Last Post by waveydaveywaves
0

mysql_query("UPDATE tuck SET id=id--1 WHERE id >= '$id'");

you only had one "-" if you put two it automatically decreases by one each time regardless of the present state.

Edited by waveydaveywaves: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.