按钮被夹紧时立即删除

当我点击删除按钮时,我试图从数据表中删除数据,数据将被删除,以便在管理端进行快速操作,但我的代码剂量不起作用,我试图修复它,但我没有看到这里的代码有任何问题,这是我的代码


 <div class="table-responsive">

<table id="datas" class="table table-striped table-bordered fixed" style="width:100%">


    <thead style="color:black;" >

        <th>id</th>

        <th>Company Name</th>

        <th>Product Name</th>

        <th>Weight</th>

        <th>Price Per Gram</th>

        <th>Quantity</th>

        <th>Type</th>

        <th>Category</th>

        <th>Product Price</th>

        <th>Image</th>

        <th>Total Price</th>


        <th class="text-center">Actions</th>



    </thead>


    <?php

    $get = mysqli_query($conn,"SELECT * FROM stock;");

    ?>

    <tbody>


    <?php

    while ($row=mysqli_fetch_array($get)) {

        $id=$row['id'];

        $company=$row['company_name'];

        $name=$row['product_name'];


        $weight=$row['weight'];

        $price_per_gram=$row['price_per_gram'];

        $quantity=$row['quantity'];


        $type=$row['type'];

        $category=$row['category'];

        $price=$row['product_price'];

        $img=$row['img'];

        $total=$row['total_price'];

        ?>

            <tr>

            <td ><?php echo $id;?></td>

            <td><?php echo $company;?></td>

            <td><?php echo $name;?></td> 

            <td><?php echo $weight;?> g</td>

            <td><?php echo $price_per_gram;?> $</td>

            <td><?php echo $quantity;?></td>

            <td><?php echo $type;?></td>

            <td><?php echo $category;?></td>

            <td><?php echo $price;?></td>

            <td>

    <?php } ?>

    </tbody>

</table>



我给删除按钮一个值,当点击,所以它会删除与该值,但它似乎没有工作,任何人都可以帮助我


森栏
浏览 95回答 1
1回答

慕哥6287543

你必须把桌子放在标签里面<form></form><div class="table-responsive"><form><table id="datas" class="table table-striped table-bordered fixed" style="width:100%">&nbsp; &nbsp; <thead style="color:black;" >&nbsp; &nbsp; &nbsp; &nbsp; <th>id</th>&nbsp; &nbsp; &nbsp; &nbsp; <th>Company Name</th>&nbsp; &nbsp; &nbsp; &nbsp; <th>Product Name</th>&nbsp; &nbsp; &nbsp; &nbsp; <th>Weight</th>&nbsp; &nbsp; &nbsp; &nbsp; <th>Price Per Gram</th>&nbsp; &nbsp; &nbsp; &nbsp; <th>Quantity</th>&nbsp; &nbsp; &nbsp; &nbsp; <th>Type</th>&nbsp; &nbsp; &nbsp; &nbsp; <th>Category</th>&nbsp; &nbsp; &nbsp; &nbsp; <th>Product Price</th>&nbsp; &nbsp; &nbsp; &nbsp; <th>Image</th>&nbsp; &nbsp; &nbsp; &nbsp; <th>Total Price</th>&nbsp; &nbsp; &nbsp; &nbsp; <th class="text-center">Actions</th>&nbsp; &nbsp; </thead>&nbsp; &nbsp; <?php&nbsp; &nbsp; $get = mysqli_query($conn,"SELECT * FROM stock;");&nbsp; &nbsp; ?>&nbsp; &nbsp; <tbody>&nbsp; &nbsp; <?php&nbsp; &nbsp; while ($row=mysqli_fetch_array($get)) {&nbsp; &nbsp; &nbsp; &nbsp; $id=$row['id'];&nbsp; &nbsp; &nbsp; &nbsp; $company=$row['company_name'];&nbsp; &nbsp; &nbsp; &nbsp; $name=$row['product_name'];&nbsp; &nbsp; &nbsp; &nbsp; $weight=$row['weight'];&nbsp; &nbsp; &nbsp; &nbsp; $price_per_gram=$row['price_per_gram'];&nbsp; &nbsp; &nbsp; &nbsp; $quantity=$row['quantity'];&nbsp; &nbsp; &nbsp; &nbsp; $type=$row['type'];&nbsp; &nbsp; &nbsp; &nbsp; $category=$row['category'];&nbsp; &nbsp; &nbsp; &nbsp; $price=$row['product_price'];&nbsp; &nbsp; &nbsp; &nbsp; $img=$row['img'];&nbsp; &nbsp; &nbsp; &nbsp; $total=$row['total_price'];&nbsp; &nbsp; &nbsp; &nbsp; ?>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td ><?php echo $id;?></td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td><?php echo $company;?></td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td><?php echo $name;?></td>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td><?php echo $weight;?> g</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td><?php echo $price_per_gram;?> $</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td><?php echo $quantity;?></td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td><?php echo $type;?></td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td><?php echo $category;?></td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td><?php echo $price;?></td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <img&nbsp; src="product_img/<?php echo $img; ?>" style="height:5rem;width:5rem;border-radius:10px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <td><?php echo $total;?></td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<td style="width: 20px"> <a href="editstock.php?id=<?php echo $id;?>" class="btn btn-gradient-primary">Edit</a>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<button class="btn btn-danger" name="delete"&nbsp; type="submit" value="<?php echo "$id" ?>">Delete</button> </td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </tr>&nbsp; &nbsp; <?php } ?>&nbsp; &nbsp; </tbody></table></form><?php&nbsp;&nbsp;if (isset($_POST['delete'])) {$delete = mysqli_query($conn,"DELETE FROM stock WHERE id= ".$_POST['delete']." ");header("location:viewstcok.php");} ?>
打开App,查看更多内容
随时随地看视频慕课网APP