Forum Moderators: coopster

Message Too Old, No Replies

id problem

         

Flolondon

8:21 am on Apr 15, 2005 (gmt 0)

10+ Year Member



if($id)mysql_query("DELETE FROM birthdays where id = $id")or die("Delete Error: ".mysql_error());

for this line, it keeps saying undefined variable...

please help

tomda

8:25 am on Apr 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It means simply that you have not defined the variable so if you type, echo $id you will get the same warning message.

Go through the lines above and see if your id variable is defined (is it a POST or GET variable?).

Flolondon

8:30 am on Apr 15, 2005 (gmt 0)

10+ Year Member



if (isset($_POST['username']))
{
$username= $_POST['username'];
}
if (isset($_POST['password']))
{
$password= $_POST['password'];
}
if (isset($_POST['id']))
{
$id= $_POST['id'];
}

this is what i did above to define the variable id. but still not working

tomda

8:52 am on Apr 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if (isset($_POST['id'])) {$id= $_POST['id'];} else {$id='1';}

It is just because your POST_id is not set, and you do not have a default value set (see else statement). Echo POST['id'] at the first line just to see.

Always have a default value for POST and GET variable. It can be NULL or any value to want.

Because you are deleting the id_row in the db, I suggest you to do the following .
1/ check if the POST id is set
2/ If yes, check that this id exist in the db (just to be sure)
3/ If not (to both) than id is NULL.

Then you can

if($id) {mysql_query("DELETE FROM birthdays where id = $id")or die("Delete Error: ".mysql_error());}

Flolondon

9:01 am on Apr 15, 2005 (gmt 0)

10+ Year Member



thanks that one helped. thanks a lot