我有一个表,其中包含从数据库中循环出来的所有文章以及DELETE链接,该链接将帖子的ID发送到处理程序以进行删除,但我必须单击两次才能删除。
这是处理程序中的删除代码:
if($_GET['deleteArticleId']){
// Delete article
$crudObject = new CrudClass();
$row_id = $_GET['deleteArticleId'];
$table_name = "28uge_cms_newsarticles";
$crudObject->delete($table_name, $row_id);
// Delete article links to categories
$crudObject = new CrudClass();
$sql = "DELETE FROM 28uge_cms_newsarticles_categories WHERE newsarticles_id = {$_GET['deleteArticleId']}";
$crudObject->sendQueryToDatabase($sql);
// Delete article links to images
$crudObject = new CrudClass();
$sql = "DELETE FROM 28uge_cms_newsarticles_images WHERE newsarticles_id = {$_GET['deleteArticleId']}";
$crudObject->sendQueryToDatabase($sql);
header('location: ../admin/newsview.php');
exit;
}
“//删除文章链接到类别”和“//删除文章链接到图像”第一次工作,但“//删除文章”仅在按下删除链接两次时才有效。
这是删除功能代码:
public function delete($table_name, $row_id){
// Putting together the SQL string.
$sql = "DELETE FROM $table_name WHERE id = $row_id";
// Sending the SQL string off to the database.
$this->dbConn -> query($sql);
}
我无法弄清楚是什么导致了这个错误,所以非常感谢帮助!