Mystixs Posted May 13, 2007 Share Posted May 13, 2007 Hello.I have run into some trouble. I have my admin panel, and I want to delete news by pressing a button. But not sure how to do that. I don't want to create a new page to delete news... Here is my code: if ($_GET['page']=="news") { echo "<h3 align='center'>" . 'News' . "</h3>"; echo "<table border='1' align='center'>"; echo "<tr>"; $result = mysql_query("SELECT * FROM news ORDER BY id DESC"); while($row = mysql_fetch_array($result)) echo "<td width='500px'>" . '<b>' . $row['name'] . '</b>' . " Delete" . '<br>' . '<small>Posted on: ' . $row['date'] . '</small>' . '<br>' . $row['message'] . "</td>" . "</tr>"; echo "</table>"; } Now, were the Delete word is, I want that to be a link that runs a Mysql Delete Quary when pressed without going to a new page.Thanks for the help! Link to comment Share on other sites More sharing options...
Anders Moen Posted May 13, 2007 Share Posted May 13, 2007 Let's see...*parts taken from my adminpanel* $id = intval($_GET['id']);mysql_query("DELETE FROM table WHERE id = '$id'");echo 'News #' . $_GET['id'] . ' was deleted from our database'; Then you write like yourpage.php?id=some_number and then if it exists it will be deleted from your database and if not: it won't be deleted.* Remember you need some more code, but I think you will do fine * Link to comment Share on other sites More sharing options...
Mystixs Posted May 13, 2007 Author Share Posted May 13, 2007 Well, that will require a new page being made. I am trying to shove as much as I can into 1 page...With several pages I get lost with everything. Link to comment Share on other sites More sharing options...
Anders Moen Posted May 13, 2007 Share Posted May 13, 2007 No? You can put that code into another site... Link to comment Share on other sites More sharing options...
Lulzim Posted May 13, 2007 Share Posted May 13, 2007 Well, that will require a new page being made. I am trying to shove as much as I can into 1 page...With several pages I get lost with everything.of course you can do that in on pagefor example news.php will show the news and news.php?action=delete&id=3 will delete an entry<?if($_GET["action"]=='delete'){ //code to delete goes here}if ($_GET['page']=="news"){ //code to display news} Link to comment Share on other sites More sharing options...
Mystixs Posted May 13, 2007 Author Share Posted May 13, 2007 Ohh Ok. Thanks. Sorry, I'm still new at this. Link to comment Share on other sites More sharing options...
sajan Posted May 14, 2007 Share Posted May 14, 2007 use header() to redirect to this page after deleting Link to comment Share on other sites More sharing options...
justsomeguy Posted May 14, 2007 Share Posted May 14, 2007 Or pop up a new window using Javascript to do the delete and refresh the parent page. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.