douyueju2912 2018-10-06 06:24
浏览 51
已采纳

从while删除记录的查询不起作用

I used it as a key id to delete the specific row in while loop, but I don't know where is the problem and give an error.

<?php

$db=mysqli_connect("localhost","root","root","done");

if(isset($_POST['deleteId'])){
    $query5 = "DELETE FROM dones WHERE id = '$_POST[deleteId]'"; 
    $result5=mysqli_query($db,$query5);
} 

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

    echo '<div class="accordion" id="accordionExample">';
    echo '<div class="card" style="margin-left:10px; margin- 
            right:10px;">';
    echo '<div class="card-header">';
    echo '<h5 class="mb-0">';
    echo '<form action="" method="POST" enctype="multipart/form-data">';
    echo  '<button class="btn btn-link" style="text-decoration:none; font- 
            family:Times New Roman, Times, serif; font-size:18px; " type="button" 
            data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" 
            aria-controls="collapseOne">';
    echo   $row['title'];
    echo '</button>';
    echo '</h5>';
    echo '</div>';

    echo '<div id="collapseOne" class="collapse show" aria- 
    labelledby="headingOne" data-parent="#accordionExample">';
    echo  '<div class="card-body">';

    // Content Of new banner

    echo '<h5 style="text-align:left; margin-left:20px; margin-top:20px;">
            <small>Title</small></h5>';
    echo '<input style="width:290px; margin-left:158px; height:30px; 
            margin-top:-30px;" name="title" type="text" 
            class="form-control" placeholder="Title">';
    echo ' <br>';
    echo ' <div class="custom-file" style="height:10px; width:290px; margin- 
                right:1050px; top-padding:20px; float:right;">';
    echo ' <input type="file" name="uploadfile" class="custom-file-input" 
            id="validatedCustomFile">';
    echo ' <label class="custom-file-label" for="validatedCustomFile">Choose 
            file...</label>';
    echo ' </div>';
    echo ' <h5 style="text-align:left; margin-left:20px;"><small>File</small> 
            </h5>';
    echo ' <br>';
    echo ' <h5 style="text-align:left; margin-left:20px;"><small>Banner 
            Image</small></h5>';
    echo ' <div style="height:130px; width:290px; border-width:1px; border- 
            style:solid; float:right; margin-right:1050px; margin-top:-15px;">';


    $sql = "SELECT image FROM dones where status=1";
    $result = mysqli_query($db,$sql);
    $data = mysqli_fetch_array($result);
    echo '<img src= "images/'.$data['image'].'" style="height:130px; 
            width:290px;">';

    echo '</div>';
    echo '<br>';
    echo '<br>';
    echo '<br>';
    echo '<br>';
    echo '<br>';
    echo '<br>';  
    echo '<h5 style="text-align:left; margin-left:20px;"> 
            <small>Status</small></h5>';
    echo '<select name="status" id="" style="width:290px; float:right; 
            margin-right:1050px; margin-top:-25px;">';
    echo '<option value="1" name="enable">Enable</option>';
    echo '<option value="0" name="disable">Disable</option>';
    echo '</select>';
    echo '<br>';
    echo '<br>';
    echo '<button type="submit" name="tbsubmit"  style="margin-left:250px;" 
            class="btn btn-primary">Save Changes</button>';  
    echo '<button type="submit" name="deletesubmit"  style="margin- 
            left:250px;"  class="btn btn-primary"><a href="'? 
            deleteId=$row['id']'">Delete</a></button>'; 
    echo '</div>';
    echo '</form>';
    echo '</div>';
    echo  '</div>';
    echo '</div>';
    echo '</div>';
    echo '</div>';
}   

?>

Delete is the logic for deleting

Actually I used from this logic

and I write inside the delete button at the end I also used instead of keyID in my database just id. and I don't what is the main problem here.

this is the error

enter image description here

enter image description here

  • 写回答

2条回答 默认 最新

  • doulu7174 2018-10-06 07:03
    关注

    you can use this link to delete:

    echo "<button type='submit' name='deletesubmit' style='margin-left:250px;'  class='btn btn-primary'><a href='?deleteId={$row['id']}'>Delete</a></button>";
    
    //and now the if statemant:
    
    if(isset($_GET['deleteId'])){
       $query5 = "DELETE FROM dones WHERE id='{$_GET['deleteId']}'"; 
       $result5=mysqli_query($db,$query5);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler