I have a site where users can upload files and the list of files is pulled from a SQL database. The problem is, I also want users to be able to delete files both from the database and the directory but I want a confirmation for this process before the record is deleted. Here's the code I'm using:
<?php
//Sample Database Connection Syntax for PHP and MySQL.
//Connect To Database
$hostname="hostname";
$username="username";
$password="password";
$dbname="dbname";
mysql_connect($hostname,$username, $password);
mysql_select_db($dbname);
# Check If Record Exists
$query =
"SELECT FileID,FileLoc,FileName,FileUpdate,DBUser
FROM SGD_FT
WHERE DBUser='$_SESSION[MM_Username]'";
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
#table tag
$linktypesave = "";
for ($i=1;$i<=$num_rows;$i++)
{
#$row is next row--in an array;
$row=mysql_fetch_row($result);
if ($linktypesave <> $row[3])
{
$linktypesave = $row[3];
echo "<table>";
echo "<tr>";
echo "<td width=200 class=Header2>";
print "<u>" . File . "</u>";"<br>";
echo "</td>";
echo "<td width=200 class=Header2>";
print "<u><font size = 3>" . Date . " " . Updated . "</u>";
echo "</td>";
echo "<tr>";
echo "</table>";
}
echo "<table>";
echo "<tr>";
echo "</td>";
echo "<td width=200 valign=top class=MainText>";
print ("<a href=\"" . $row[1] . "\" target=_blank>" . $row[2] . "</a> ");
echo "</td>";
echo "<td width=150 valign=top class=MainText>";
print "<i>" . $row[3];
echo "</td>";
echo "<td width=150 valign=top class=MainText>";
print ("<a href=\"../r3U.php?FileID=" . $row[0] . "\" class=Button onClick='return confirmSubmit({
var agree=confirm('Are you sure you wish to continue?');
if (agree)
return true ;
else
return false ;
}
)'>" . " " . Delete . " " . "</a> ");
print ("<a href=\"../r4U.php?FileID=" . $row[0] . "\" class=Button>" . " " . Edit . " " . "</a> ");
echo "</td>";
echo "</table>";
}
?>
Any suggestions?