当我尝试删除按钮时,没有错误,页面刷新,但是数据不会被删除,所以我认为问题在于从行中传递ID。
到目前为止,没有其他解决方案对我有用。这是桌子的身体。
<tbody>
<?php
$server = "localhost";
$user = "Website";
$pass = "pass";
$db = "db";
$conn = new mysqli($server, $user, $pass, $db);
if ($conn->connect_error)
{
die("connection to database failed");
}
$query = "SELECT * FROM koppeling";
$result = mysqli_query($conn, $query);
while($row = $result-> fetch_assoc())
{
echo "<tr>";
echo "<td>".$row['Wagon_ID']."</td>";
echo "<td name='wagon'>".$row['EPC']."
<a href='delete.php' class='table-button'
id='".$row['id']."'>Delete</a>";
echo "<td>";
echo "</td>";
echo "</tr>";
}
?>
</tbody>
delete.php
文件:
<?php
$id = $_GET['id'];
$server = "localhost";
$user = "Website";
$pass = "pass";
$db = "db";
$conn = new mysqli($server, $user, $pass, $db);
if ($conn->connect_error)
{
echo "Conn db failed";``
}
$query = "DELETE FROM koppeling WHERE id='$id';";
try
{
mysqli_query($conn, $query);
mysqli_close($conn);
header('Location: koppelen.php');
}
catch (Exception $e)
{
echo "$e";
}
?>
任何人都可以帮助我找出问题所在吗,我已经坚持了很长时间。
答案 0 :(得分:1)
如果不是这样
while($row = $result-> fetch_assoc())
{
echo "<tr>";
echo "<td>".$row['Wagon_ID']."</td>";
echo "<td name='wagon'>".$row['EPC']."
<a href='delete.php' class='table-button'
id='".$row['id']."'>Delete</a>";
echo "<td>";
echo "</td>";
echo "</tr>";
}
将此
while($row = $result-> fetch_assoc())
{
echo "<tr>";
echo "<td>".$row['Wagon_ID']."</td>";
echo "<td name='wagon'>".$row['EPC']."
<a href='delete.php?id=".$row['id']."' class='table-button'
id='".$row['id']."'>Delete</a>";
echo "<td>";
echo "</td>";
echo "</tr>";
}
答案 1 :(得分:0)
如果您将表单与POST请求或ajax一起使用,而不是使用链接,那会更好。
如果您真的想用这种方法,可以将查询字符串添加到href属性。
tmp.Color = xlRange.Cells[i, j].Interior.Color.ToString();
答案 2 :(得分:-2)
您必须更改以下行
$ query =“从koppeling那里删除,其中id ='$ id';”;
到
$ query =“从koppeling删除,其中id ='”。$ id。“';;;;
以便在查询中正确填充ID值