Jump to content

Help With the Delete function


Mystixs

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...