sdm Posted March 2, 2007 Share Posted March 2, 2007 Hi all, I have now managed to get the script to display all records, but I can't get it to delete any records. The edit works fine but can someone show me how to add a delete button as well so that I can delete the one chosen with the current id please. This is the code I have so far: <? //include our database connection file include('dbconnect.php'); if($_POST['action']=="doedit"){ //grab the post vars $title = $_POST['title']; $id = $_POST['id']; $sector = $_POST['sector']; $location = $_POST['location']; $salary = $_POST['salary']; $details = $_POST['details']; //update the database $news = "UPDATE news SET title='$title', sector='$sector', location='$location', salary='$salary', details='$details' WHERE id = $id"; $editnews = mysql_query($news); echo("news edited."); } //print the news titles, with links to the edit page $getnews = mysql_query("select * from news ORDER BY id DESC"); while($r=mysql_fetch_array($getnews)){ extract($r); echo("> <a href=editjobs.php?id=$id&action=edit>$title</a><br />"); } echo("<br /><br />"); //if we are editing a news item, print the following.. if($_GET['action']=="edit"){ $id = $_GET['id']; $getnews = mysql_query("select * from news WHERE id=$id"); while($r=mysql_fetch_array($getnews)){ extract($r); //our form ?> <form action="editjobs.php" method="POST"> <input type="text" name="title" value="<? echo($title); ?>" /><br /> <input type="text" name="sector" value="<? echo($sector); ?>" /><br /> <input type="text" name="location" value="<? echo($location); ?>" /><br /> <input type="text" name="salary" value="<? echo($salary); ?>" /><br /> <textarea name="details" rows="6" cols="50"><? echo($details); ?></textarea> <input type="submit" value="edit" /> <input type="hidden" name="id" value="<? echo($id); ?>" /> <input type="hidden" name="action" value="doedit" /> </form> <? } } ?> Link to comment https://forums.phpfreaks.com/topic/40938-how-easy-is-it-to-add-a-delete-function/ Share on other sites More sharing options...
fert Posted March 2, 2007 Share Posted March 2, 2007 $news = "DELETE FROM news WHERE id = $id"; Link to comment https://forums.phpfreaks.com/topic/40938-how-easy-is-it-to-add-a-delete-function/#findComment-198242 Share on other sites More sharing options...
sdm Posted March 2, 2007 Author Share Posted March 2, 2007 Thanks for the reply. I'm quite new to this, where do I add the code you have shown me. Can I have a delete button next to the 'Edit' button? Thanks, SDM Link to comment https://forums.phpfreaks.com/topic/40938-how-easy-is-it-to-add-a-delete-function/#findComment-198250 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.