0

我有以下代码,计划是显示数据库中的数据,但如果作业不再可用,则允许站点管理员删除一行。我已将“删除”放在我想要删除该行的链接的位置。我尝试过使用<a href='delete1.php?del=$row[JobID]'>Delete</a>,但这只会在页面上引发错误。

<?php
include_once('db.php');

$result = mysqli_query($con,"SELECT * FROM Job ORDER BY JobID");

echo "<table border='1'>
      <tr>
          <th>Job ID</th>
          <th>Job Title</th>
          <th>Job Description</th>
          <th>Industry</th>
          <th>Job Type</th>
          <th>Salary</th>
          <th>County</th>
          <th>Town</th>
          <th>Delete</th>
     </tr>";

while($row = mysqli_fetch_array($result))
{
    echo "<tr>";
    echo "<td>" . $row['JobID'] . "</td>";
    echo "<td>" . $row['JobTitle'] . "</td>";
    echo "<td>" . $row['JobDescription'] . "</td>";
    echo "<td>" . $row['Industry'] . "</td>";
    echo "<td>" . $row['JobType'] . "</td>";
    echo "<td>" . $row['Salary'] . "</td>";
    echo "<td>" . $row['County'] . "</td>";
    echo "<td>" . $row['Town'] . "</td>";
    echo "<td>" . "Delete" . "</td>";
    echo "</tr>";
}
echo "</table>";

mysqli_close($con);
?>
4

1 回答 1

1

你应该把它放在清单代码中:

 echo "<a href='delete1.php?del={$row['JobID']}'>Delete</a>";

文档

然后,在你的delete1.php你应该有类似的东西:

$jobid = intval($_GET['JobID']);
if ($jobid > 0) {
     mysqli_query($con, "DELETE FROM Job WHERE JobID=$jobid LIMIT 1");
}

(注意:这是未经测试的,可能很不安全;它只显示了如何做到这一点的概念)

于 2013-04-12T14:34:20.743 回答