My client wanna delete undesired messages from his miniblog.
A repeating zone (code below) shows these posts and include a button to delete each of them. But it doesn't works out. Where is the error?
You have some major flaws in your practices and understanding of how PHP works. PHP routines can not be run solely by a button click, they require a server side request of some kind.
You have a few options to make the server side request.
1) Have your submit button part of a form that does a POST or GET to another php page ('deletePost.php'). That page will contain your query to delete the post.
2) Have your button run javascript that makes an asynchronous HTTP requests (AJAX) to another php page ('deletePost.php')
You also have a syntax error with this code:
PHP Code:
<?php $id = $_GET["id"]?>;
mysql_query("delete from guestbook where id = $id")
?>
You closed your PHP prematurely, it should be:
PHP Code:
<?php $id = $_GET["id"];
mysql_query("delete from guestbook where id = $id")
?>
While this fixes the syntax error, it won't function like you want it(as I mentioned earlier).
As for php practices, may I suggest altering your layout as readability suffers greatly. Personally I see no reason to jump in and out of php to print HTML when you are doing it so often and with such small blocks.
you're right, kurby. I'm a newbie in PHP and I don't understand how it works out.
Please, can you post the server-side delete function and its calling on client-side (the button code)?
A lot of guys use this dreamweaver's code but it's not working. Why?
Probably because it was generated by a crappy piece of software rather than a sentient programmer. I don't know how people have the nerve to click some buttons in Dreamweaver without having a clue about what is actually going on, then charge clients for this stuff! If you don't know what you're doing, read some books and learn before taking people's money in return for some insecure spaghetti code spat out by your editor. Sorry if that sounds harsh but this practice is something of an annoyance to me.
Last edited by Mindzai; 03-25-2010 at 02:08 PM.
The first rule of Tautology Club is the first rule of Tautology Club.
Mindzai -> First of all, I'm a newbie in php and just that would sufficy for you have some respect to me. Secondly, I earn for the whole project not for just a bit of code that is problematic. I can't spend too much time studying by now because I have deadlines to meet. If you're not interested to help your comments are not appreciated.
Kurby, I've changed the form method to GET and nothing. Also changed all (server and client-side) to POST and nothing. Probably the error is when the variable id is passed to php but I can't see where is the bug.
------------------------------------------------------------------------
Answer if you know; nobody is obligated to reply.
Your actually not passing a "id" value. You need to create an input element of some kind with name="id" and value="x". Then you can access $_GET['id'] which will be 'x'.
ok, it is working, the records are deleted. Only one problem: the script only deletes the first record, not what I chose. Each click deletes, id 5 , 6 ,7 and so on. Why?
The delete button and "id" hidden field are on the repeating zone. It should work, right?
Bookmarks