dongshu7162 2018-11-03 20:35
浏览 45
已采纳

删除数据库中的值 - PHP

I should delete values ​​from the database but end now, the only result that I managed to get is to make a certain value null, and then this then becomes invalid, but if I want to repeat the process I can no longer do it. My goal would be to freely delete all the products I want from a given event, place the code for deletion:

<a href="#elimina<?php echo $row['impianto_id_campagna']; ?>" data-toggle="modal" class="btn-floating btn-sm btn-pin "><span class="glyphicon glyphicon-trash"></span> <i class='fa fa-remove' aria-hidden='true'></i></a

modal:

<div class="modal fade" id="elimina<?php echo $row['impianto_id_campagna']; ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header text-center">
                <h4 class="modal-title w-100 font-weight-bold">Elimina Impianto</h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>

            <?php

             $elimina=mysqli_query($connessione,"select * from campagne_cliente where impianto_id_campagna='".$row['impianto_id_campagna']."'");


             $row_due=mysqli_fetch_array($elimina);

            ?>


            <div class="modal-body mx-3">

            <h5 style="text-align: center;">Eliminare l'impianto dalla campagna?</h5>

            </div>


            <div class="modal-footer d-flex justify-content-center">
                <a href="eliminainfo.php?impianto_id_campagna=<?php echo $row['impianto_id_campagna']; ?>" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span>Elimina</a>
            </div>
        </div>
    </div>
</div>

delete_page:

<?php

include '../../connessione.php';

$impianto_id_campagna=$_GET['impianto_id_campagna'];

mysqli_query($connessione,"UPDATE campagne_cliente SET impianto_id_campagna = NULL WHERE impianto_id_campagna = '$impianto_id_campagna'");

header('location: campagne.php');
?>

my db structure: my db structure

in the picture you will see a value set to 0, but if I later want to set another value to 0, I can not do it, the maximum would be to delete the whole row, starting from the id_impianto_campagna

  • 写回答

2条回答 默认 最新

  • duanca3415 2018-11-03 20:41
    关注

    If you are deleting the record against primary key then replace:

    "UPDATE campagne_cliente SET impianto_id_campagna = NULL WHERE 
    impianto_id_campagna = '$impianto_id_campagna'"
    

    with:

    "DELETE FROM campagne_cliente WHERE impianto_id_campagna = 
    $impianto_id_campagna"
    

    and check it again.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1