我有一个表,其中一列应该有一个名为delete的按钮。但是我尝试了不同的代码示例,但删除按钮仍然不起作用。
这里的代码显示了删除按钮,它的工作原理非常好:
echo '<td><a class="btn btn-default" href="delete.php?courseId='.$row['courseId'].'">Delete</a></td>';
,下一个代码是我的删除代码:
<?php include("dbconnect.php");
$courseId =$_GET['courseId'];
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "DELETE FROM course WHERE courseId= $courseId";
$q = $pdo->prepare($sql);
$q->execute(array($courseId,$courseName,$desc));
Database::disconnect();
header("Location: courseList.php");
?>
提前致谢〜
答案 0 :(得分:3)
echo '<td><a class="btn btn-default" href="delete.php?courseId='.$row['courseId'].'">Delete</a></td>';
您错过了?
,表示查询参数的开始。
答案 1 :(得分:-1)
你很亲密
<?php include("dbconnect.php");
$courseId =$_GET['courseId'];
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "DELETE FROM course WHERE courseId= :courseId";
$q = $pdo->prepare($sql);
$q->execute(array(':courseId'=>$courseId));
Database::disconnect();
header("Location: courseList.php");
?>