muddy9494 Posted June 9, 2009 Share Posted June 9, 2009 Ok, i do not know how to set this up. I want it in my admin panel im making to show it like this: Where i put the blue i want it to say delete and when i click that it deletes the row that the news post is on. Any code you need to see (The Posting News, The Showing News) just ask. Cuz im not sure what you need to see. Quote Link to comment https://forums.phpfreaks.com/topic/161455-solved-delete-row-news-system/ Share on other sites More sharing options...
redarrow Posted June 9, 2009 Share Posted June 9, 2009 Have you worked out, how to add the delete button, in the position you want it, with html yet? Quote Link to comment https://forums.phpfreaks.com/topic/161455-solved-delete-row-news-system/#findComment-852021 Share on other sites More sharing options...
muddy9494 Posted June 9, 2009 Author Share Posted June 9, 2009 Well, i know how to make it link to something, i know html. the delete button will go where i put the blue lines( im to lazy to put it in now...) it will link to deletepost.php. But i dont know how to correctly delete only the row that the post is on. it is on an auto increasing id system. Quote Link to comment https://forums.phpfreaks.com/topic/161455-solved-delete-row-news-system/#findComment-852027 Share on other sites More sharing options...
xtopolis Posted June 9, 2009 Share Posted June 9, 2009 You would probably use a $_GET argument at the end of the url. When you loop through the stories, select the auto increment column as well and have it print something like this: //... while (/* database select stuff */) { echo $row['PostTitle'] . ' <a href="delete.php?id=' . $row['PostID'] . '">[Delete]</a>'; echo '<br>'; } And have delete.php "Delete" the post with that PostID (assuming PostID is the name of the auto increment column). Btw, don't delete things, rather set a flag on or off showing it as "delete", but keep it in the system. When you select, just add a condition "WHERE deleted = 0" or something. Quote Link to comment https://forums.phpfreaks.com/topic/161455-solved-delete-row-news-system/#findComment-852039 Share on other sites More sharing options...
muddy9494 Posted June 9, 2009 Author Share Posted June 9, 2009 I got that part, i want to know what would i put in delete.php? Well, i actually just dont know how to code delete.php correctly. Quote Link to comment https://forums.phpfreaks.com/topic/161455-solved-delete-row-news-system/#findComment-852040 Share on other sites More sharing options...
xtopolis Posted June 9, 2009 Share Posted June 9, 2009 delete.php would primitively be something like this: //database connection stuff //grab postid from the url $id = intval($_GET['id']); //check if it exists $sql = "SELECT PostID FROM posts WHERE id='$id'"; $result = $db->query($sql); if(mysql_num_rows($result) == 1){ $delete = "UPDATE posts SET deleted=1 WHERE PostID='$id'"; //exists, "delete" it if(!$db->query($delete)) { echo mysql_error(); }else{ echo 'Post has been deleted.'; } }else{ //post doesn't exist, or multiple matches (shouldn't have multiple on auto inc ..) echo 'No post exists with that post id.'; } Quote Link to comment https://forums.phpfreaks.com/topic/161455-solved-delete-row-news-system/#findComment-852049 Share on other sites More sharing options...
muddy9494 Posted June 9, 2009 Author Share Posted June 9, 2009 Not working. Fatal error: Call to a member function on a non-object in /home/www/******/********/delete.php on line 16 Line 16 is: $result = $db->query($sql); $db and $sql isnt in my mysql.php file. What should the $db and $sql =? Quote Link to comment https://forums.phpfreaks.com/topic/161455-solved-delete-row-news-system/#findComment-852055 Share on other sites More sharing options...
xtopolis Posted June 9, 2009 Share Posted June 9, 2009 I was using a class for my $db object. $result = $db->query($sql) is the same as $result = mysql_query($sql); $sql refers to the query "SELECT PostID FROM posts WHERE id='$id'". I just prefer to store it in a variable first. It could all together be $result = mysql_query("SELECT PostID FROM posts WHERE id='$id'"); (or something close to that) You will get the same problem a few lines down when it deletes. Quote Link to comment https://forums.phpfreaks.com/topic/161455-solved-delete-row-news-system/#findComment-852058 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.