Cant get it to delete

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lmhart
Forum Newbie
Posts: 15
Joined: Tue Apr 14, 2009 1:05 pm

Cant get it to delete

Post by lmhart »

I have a page that lists the user and has an option to delete the record. But I can not get it to delete the record. I believe that I am passing the correct information but it just will not delete. It just goes to delete.php and displays a blank name. The pop up that I have before it switches pages post the correct info. Where am I going wrong?

Code: Select all

 
->addColumnAfter('actions', '<a href="#edit.php?id=$user_id$">Edit</a>
 - <a href="delete.php?id=$id_user$" onclick="return confirm(\'Are you sure you want to delete user $id_user$?\')">Delete</a>
 ', 'Actions', array('align' => 'center'))
 
delete.php

Code: Select all

 
<php
 
include 'dbc.php';
$id_user = $_GET[id];
echo $id_user;
echo "<br>";
echo $id;
mysql_query("Delete From users where id_user = $id_user");
 
?>
 
User avatar
markusn00b
Forum Contributor
Posts: 298
Joined: Sat Oct 20, 2007 2:16 pm
Location: York, England

Re: Cant get it to delete

Post by markusn00b »

Firstly, you should be wrapping your array indexes with quotes (single quotes, preferably). I won't go into why - just do it.

Next, I imagine the reason you are not seeing any records deleted is because you have an extra '$' on the end of your $user_id variable.

You should have been able to debug this very rapidly. When things don't happen the way you expect them to, have a look at what the variables contents are. In this case, you would have noticed that $_GET['id'] (notice the quotes) held something like '10$'. You would have then deduced that the trailing dollar sign was the problem. Then you would have located where this dollar sign was being added.

Debugging is a HUGE part of programming.
Post Reply