Jump to content

Recommended Posts

I want to make delete button to delete the record from mysql database using PHP. I have made the button in HTML and apply some formatting as below, but i am not coming up on actual logic, so plz help.

 

$comment = $_POST[txt_comment];

$comment_len = strlen ($comment);

$delete = $_POST["del"];

if ( $delete > $comment_len )

{

function foo($comment)

{

unset($comment);

}

}

else

{

echo ($comment);

}

 

<input type="submit" value ="Delete" name = "del">

Basically you need to get the ID of post attached to the form. When your code grabs the info from the database, you then need to add a hidden field to the form and have it hold the id of the post.

 

Then when that delete button is hit, you will run a query to delete.

 

<input type="hidden" name="commentId" value="<?php echo $commentId; ?>" />

 

<input type="submit" value ="Delete" name = "del">

 

<?php

if(isset($_POST['del']) && isset($_POST['commentId']))
{
  $id = $_POST['commentId'];
  $query = "DELETE FROM tableName WHERE fieldName = '$id'";
  $result = mysql_query($query);
}

?>

 

Something like that is what you need to do. You will nee to change things to your actual field and table names, but that is the principle.

 

Nate

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.