Jump to content

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());  
?>

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.