我有 2 个文件可以帮助我删除文档和更新数据库。我的第一个文件包含一个带有删除按钮的表单和一个名为 remove() 的 javascript 函数。第二个 php 页面将删除它不返回任何结果的文件。
Remove.php 的代码(调用 remove() 函数时):
$Doc=$_GET['Doc']; //Value get from remove() function
$ID= intval($_POST['ID']);
$FirstReport= $_POST['FirstReport'];
$SecReport = $_POST['SecReport'];
$FirstReportPath= $_POST['FirstReportPath'];
$SecReportPath = $_POST['SecReportPath '];
$DB = new PDO('sqlite:/database/Student.db');
//If i click remove firstreport button, i'll check it to see if it's the same
if(($Doc) == ($FirstReport))
{
$result= $DB->query("Update Student set FirstReport='No' WHERE ID=".$ID);
//This unlink should remove the document file from the path.
unlink($FirstReportPath);
echo "success";
}
else
{
//same code repeated as if statement
}
Javascript函数
function RemoveDoc(Doc)
{
xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","functions/Resubmit.php?Doc="+Doc,true);
xmlhttp.send();
document.getElementById("RemoveMsg").innerHTML=xmlhttp.responseText;
return false;
}
我确实尝试过警告(Doc)并且文档名称确实显示但在第二个 remove.php 上,它没有运行任何编码。尝试“GET”/“POST”也得到相同的结果。好心提醒。