douliu8327
2016-01-05 11:43
浏览 32
已采纳

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

I'm trying to make it so when i click a "x" it will delete the entire row. I've linked each record to my jobRef however the delete isn't working.

This is what i've got so far;

<?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>";
?>

Heres my 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');
}
}
?>
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • drjv5597 2016-01-05 11:45
    已采纳

    You simply write your query , Forget to execute it.

    $query1= ("DELETE FROM person WHERE id='$id'");
    

    You need to execute it

    $pdo->query("DELETE FROM person WHERE id='$id'");
    

    Or better to use bind statement

    $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";
        }
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题