我正在为php分配编写一些代码,我从URL获得了正确的ID,该表显示了与该人相对应的所有正确记录,但是我的删除按钮无法正常工作,我要么删除了有关此人的表格,否则我会出错。
我的头部上方的PHP部分
<?php require "config/config.php"; ?>
<?php
if(isset($_GET['upd'])){
$id = $_GET['upd'];
$query = "SELECT * FROM persons WHERE id=$id";
$fire = mysqli_query($con,$query) or die("Can not fetch the data.".mysqli_error($con));
$user = mysqli_fetch_assoc($fire);
}
?>
我在头部上方的删除部分
<?php
if(isset($_GET['delweight'])){
$weightid = ($_GET['weightid']);
$query = "DELETE FROM personweight WHERE weightid = $weightid";
$fire = mysqli_query($con,$query) or die("Can not delete the data from database.". mysqli_error($con));
if($fire) echo "Data deleted from database";
}
?>
带有删除记录的我的表
<table class="table table-striped table-dark" id="weightTable">
<thead>
<tr><th>weightid</th><th>Weight</th><th>Date</th><th>Delete</th></tr>
</thead>
<tbody>
<?php
$query = "SELECT * FROM personweight WHERE id=$id";
$fire = mysqli_query($con,$query) or die("can not fetch data from datase ".mysqli_error($con));
if(mysqli_num_rows($fire)>0){
while($user = mysqli_fetch_assoc($fire)){ ?>
</tr>
<td><?php echo $user['weightid'] ?></td>
<td><?php echo $user['weight'] ?></td>
<td><?php echo $user['added'] ?></td>
<td>
<a href="<?php $_SERVER['PHP_SELF'] ?>?delweight=<?php echo $user['id'] ?>" class="btn btn-sm btn-danger">Delete</a>
</td>
</tr>
<?php }} ?>
</tbody>
</table>