Hey everyone.
I’m working at a script that will delete a file from the server and delete the corresponding row in the database. The script is a Online Notes system for a small high school I am working with.
Each row of the script will contain the fields TeacherName, NotesTitle, FileName, CourseName. FileName contains the path of the file that I want to have deleted. When I run my delete script (below) I get an error:
[QUOTE]
Could not successfully run query (DELETE TeacherName, NotesTitle, FileName, CourseName From Notes WHERE NotesTitle = ‘Testing 1, 2, 3’) from DB: Not unique table/alias: ‘TeacherName’
I’m not exactly sure what’s on the go, but here is the script:
[code=php]<?php
session_register(“User”);
if (!isset($_SESSION[‘User’]))
{
// User not logged in, redirect to login page
Header(“Location: loginsys.php”);
}
if ($_SESSION[‘User’] == “Student”)
{
//Students cannot access this section
Header(“Location: loginsys.php”);
}
/*select note and filename from database*/
$conn = mysql_connect(“$host”,”$username”,”$password”);
if (!$conn) {
echo “Unable to connect to DB: ” . mysql_error();
exit;
}
if (!mysql_select_db(“dbname”)) {
echo “Unable to select the Bay d’Espoir Database: ” . mysql_error();
exit;
}
$sql = “Select FileName From Notes”;
$result = mysql_query($sql);
if (!$result) {
echo “Could not successfully run query ($sql) from DB: ” . mysql_error();
exit;
}
if (mysql_num_rows($result) == 0) {
echo “No rows found, nothing to print so am exiting”;
exit;
}
/*done selecting notes and filename*/
//Delete notes!
if (is_file($FileName))
if (@unlink($FileName))
echo “Removed file $FileName”;
$sqldel = “DELETE TeacherName, NotesTitle, FileName, CourseName
From Notes
WHERE NotesTitle = ‘$NotesTitle'”;
$resultdel = mysql_query($sqldel);
if (!$resultdel) {
echo “Could not successfully run query ($sqldel) from DB: ” . mysql_error();
exit;
}
if (mysql_num_rows($resultdel) == 0) {
echo “No rows found, nothing to print so am exiting”;
exit;
}
else
echo “Could not remove file! $FileName”;
?>
<html>
<head>
<title>Notes Deleted</title>
<link href=”CssFiles/body_frame.css” rel=”stylesheet” type=”text/css” />
</head>
<body>
<h3><i><? echo $NotesTitle; ?> deleted!</i></h3>
<p>To delete more notes, <a href=”delete_notes.php”>click here.</a></p>
<p>If you are done<a href=”javascript:window.close();”>click here.</a></p>
<!– Make sure content goes before this!!–>
<br> <br>
</body>
</html>