Jump to content

Recommended Posts

Ok, i do not know how to set this up. I want it in my admin panel im making to show it like this:

delete.jpg

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.

Link to comment
https://forums.phpfreaks.com/topic/161455-solved-delete-row-news-system/
Share on other sites

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.

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.

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.';

}

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.