我正在尝试做到这一点,以便当我单击“x”时它将删除整行。 我已将每条记录链接到我的 jobRef,但删除不起作用。
这就是我到目前为止所得到的;
<?php
$status = 'available';
$stmt = $pdo->query('SELECT * FROM jobs WHERE jobStatus = "' . $status . '"');
$results = $stmt->fetchAll();
echo "<table><tr><td>Job Reference</td><td>Description</td>";
foreach ($results as $row) {
echo "<tr><td>".$row['jobRef']."</td>","<td>".$row['jobDescription']."</td>";
echo "<td><a href='edit.php?id=".$row['jobRef']."'>Edit</a></td>";
?>
这是我的delete.php
<?php
require 'mysqlcon.php';
?>
<?php
if(isset($_GET['id']))
{
$id=$_GET['id'];
$query1= ("DELETE FROM person WHERE id='$id'");
if($query1)
{
header('location:Vacancies.php');
}
}
?>
最佳答案
您只需编写查询,忘记执行它。
$query1= ("DELETE FROM person WHERE id='$id'");
你需要执行它
$pdo->query("DELETE FROM person WHERE id='$id'");
或者更好地使用bind语句
$sth =$pdo->prepare('DELETE FROM person WHERE id=:id');
$sth->bindValue(':id', $id, PDO::PARAM_INT);
$sth->execute();
$count = $sth->rowCount();
if($count>0)
{
header('location:Vacancies.php');
}else{
echo "Error in delete";
}
关于php - PDO PhP - 从选择 ID 中删除查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34610943/