PDO PhP-从选择ID中删除查询


PDO PhP - Delete query from selecting ID

我正在努力使它在单击"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>";
?>

这是我的代理人.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'");

或者最好使用绑定语句

$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";
    }