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.
Bookmarks