我是 php 新手并试图添加一个删除按钮以从列表中删除一个对象(作业),我希望删除按钮出现在每个单独的对象(作业)旁边,一旦单击此作业就会从数据库中删除桌子。下面是我的edit_jobs.php(显示特定用户的所有作业)和delete_job.php(假设从表中删除该特定作业)的代码有人可以告诉我我做错了什么,
我的 edit_jobs 页面显示特定用户发布的表中的所有工作。
<?php
include_once "connect_to_mysql.php";
$id = $userid;
$username = $_GET['username'];
$result = mysql_query("SELECT * FROM jobs WHERE user_id ='$id'")
or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
echo '<a href="job.php?id=' . $row['job_id'] . '"> ' . $row['job'] . '</a><br />';
echo 'category: ' . $row['category'] . '<br />';
echo 'description: ' . $row['description'] . '<br />';
echo '<a href="member.php?id=' . $row['userid'] . '">Clients profile</a><br />';
echo '<br />';?>
<a href="delete_job.php?job_id=<?php echo $row['job']; ?>"
onclick="return confirm('Are you sure you want to delete this book?');">
<img src="images/delete20.png" alt="Delete Book" />
</a>
<?php } ?>
delete_job 页面
<?php
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
if (!empty($_GET['job_id'])) {
$jobId = $_GET['job_id'];
require_once 'connect_to_mysql.php';
$sql = "DELETE FROM jobs WHERE job_id = ?";
$params = array($jobId);
$stmt = $link->prepare($sql);
$status = $stmt->execute($params);
if ($status == true) {
header("Location: edit_jobs.php");
}
else {
$error_info = $stmt->errorInfo();
$error_message = "failed to delete job: {$error_info[2]} - error code {$error_info[0]}";
require 'error.php';
}
}
else {
$error_message = "book id not specified";
require 'edit_jobs.php';
}
}
else {
}
?>