dongyun9120 2019-08-06 10:42
浏览 109
已采纳

表行删除按钮

When I try the delete button I get no errors and the page refreshes but the data won't be deleted, so I think the problem is in passing along the id from a row.

None of the other solutions have worked for me so far. This is the table body.

<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 file:

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

Can anyone help me figure out what is wrong, I've been stuck on this quite a while now.

  • 写回答

3条回答 默认 最新

  • duanjiaren8188 2019-08-06 10:46
    关注

    Instead if this

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

    Write this

    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>"; 
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)