Jump to content

[SOLVED] Deleting a row


sh0wtym3

Recommended Posts

I want to add a "delete this file" link under each result from my query. (I dont want it to delete an actual file, just the row in the database).

 

When you click the link it says "file deleted!", but it doesn't delete the row.

 

Below is my attempt at making it work. Once again thanks in advance.

 

{
echo "You have uploaded a total of <b>$num_rows</b> files.<br><br><br>";
}

//Loop through the result set
while($row = mysql_fetch_assoc($rs)) {
    	print "<u>File Title</u> : <b>{$row['title']}</b> <br>";
	print "File Size : ";
	print ByteSize($row['filesize']);
	print "<br>";
	print "<a href=\"?cmd=delete&id={$row['ID']}\">Delete this file</a><br><br>";
}

$id = "{$row['ID']}";

if($_GET["cmd"]=="delete")
{
    $sql = "DELETE FROM table WHERE ID = $id";
    $result = mysql_query($sql);
    echo "<b>File deleted!</b><br>";
}

//Display the navigation " . $id . "
echo $pager->renderFullNav();
?>

Link to comment
https://forums.phpfreaks.com/topic/125879-solved-deleting-a-row/
Share on other sites

print "<a href=\"?cmd=delete&id={$row['ID']}\">Delete this file</a><br><br>";

 

where the page it going to, to delete........

 

maybe $_SERVER['PHP_SELF'] might help

 

and your getting the id from a url

 

 

  $sql = "DELETE FROM table WHERE ID = ".$_GET['$id']." ";

 

heres a nice easy delete script

conf.php is your host details and pass

 

<?php
// includes
include("../template/conf.php");
// open database connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
// generate and execute query
$Id = mysql_escape_string($_GET['Id']);
mysql_query("DELETE FROM Events WHERE Id = '$Id'") 
or die(mysql_error());  
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.