Jump to content

Recommended Posts

Hi All

 

I have finished coding a very simple discussion forum but after going through everything and finding and finding out that everything works I realised I hadn't done a button to delete a line  post from the mysql db.

I can delete a row from the db manually but what I would like to know is how to delete a the row/post which the delete button/script sits next to when you are looking at the website.

Is there a way of associating a comand with a certain row without having to manually type in which row/post you want to delete.

 

Cheers all :)

Link to comment
https://forums.phpfreaks.com/topic/75350-creating-a-delete-button-script/
Share on other sites

Hi,

 

Try to save the below mentioned code in .php file and upload it to your webserver under a secured direcotry so that only you have

access to this script. Now all what you need is to provide the Primary key id and then clik delete button. Also, don't forget the connection related php code and the name of your table and primarky key.

 

<html>
<body>
<form action ="testt.php" name="thisform" method="get">
<INPUT TYPE="text" NAME="name" SIZE="30">
<br><input type="submit" value="click to delete!" onclick="submit();"><br>
<?php
$var = $_REQUEST['name'];
$delete = "delete from exam_tests where id = \"$var\"";
//you have to put the database connection code yourself.
$db = mysql_connect("localhost", "sarabicc_khaled", "khaled");
mysql_select_db("sarabicc_Test", $db) or die(mysql_errno() . ": " . mysql_error() . "<br>");
$result =mysql_query($delete);
if ($result ==true)
{ echo "The row has been deleted successfully"; }
else echo "No rows has been deleted";
?>
</form>
</body>
</html>

sorry, i submitted the code with some mistakes . here is the correct code

 

<html>
<body>
<form action ="testt.php" name="thisform" method="get">
<INPUT TYPE="text" NAME="name" SIZE="30">
<br><input type="submit" value="click to delete!" onclick="submit();"><br>
<?php
$var = $_REQUEST['name'];
//enter the table name and primary key name
$delete = "delete from tablename where primarykeyname = \"$var\"";
//you have to put the database connection code yourself.
$db = mysql_connect("", "", "");
mysql_select_db("", $db) or die(mysql_errno() . ": " . mysql_error() . "<br>");
$result =mysql_query($delete);
if ($result ==true)
{ echo "The row has been deleted successfully"; }
else echo "No rows has been deleted";
?>
</form>
</body>
</html>

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.