douyue4334 2018-03-25 04:25
浏览 57

删除查询php无法正常工作,没有任何错误,并留在同一页面上

I am unable to delete my data from a database through PHP code, though I can from phpmyadmin. I have attached both of my PHP and HTML. I tried to use the same code which is used by phpmyadmin, but there is no progress. Even with this, I am not getting alert message which I use to debug and there is no outcome.

<?php
    $conn2=mysqli_connect("localhost","root","") or die(mysql_error());
    mysqli_Select_db($conn2,"editor") or die("connot connect to the database");

    if (isset ($_GET ['delid'] ) ) {
        $deluser=$_GET['delid'];

        $alertMessage = "<div class='alert alert-danger'>
        <p> Are you sure you want to delete this record?</p><br>
        <form action='".htmlspecialchars($_SERVER['PHP_SELF']). " ?id=$deluser' method='post'>
            <input type='submit' class='btn btn-danger' id='con_del' name='con_del' value='Yes' delete!>
            <a href='location.. /listNB.php' class='close' data-dismiss='alert' aria-label='close'>X</a>
        </form>
        </div>
        ";
    }

    if (isset($_GET['con_del']))
    {
        $entry_id= $row["entry_id"];
        $sql= "DELETE FROM `editornb` WHERE `editornb`.`entry_id` = '".$entry_id."'";
        $que= mysqli_query($conn2,$sql);
             
        if ($que) {
            print'<script> alert("Sucessfully deleted!!!");</script>';
            
        } else{
            print'<script> alert("error");</script>';
            
        }

    }

?>
!DOCTYPE html>
<html>
<head>
    <title> CK EDITOR </title>
    <link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="fontawesome/fontawesome-free-5.0.6/web-fonts-with-css/css/fontawesome.min.css">
    <script src="ckeditor/ckeditor/ckeditor.js" type="text/javascript" ></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="bootstrap/js/bootstrap.min.js" type="text/javascript"></script> 
</head>
<body>
    <?php
    if (isset($alertMessage))
     echo $alertMessage;

    ?>
    <br> 
    <a class="btn btn-success" href="textareaNB.php"> Home </a>
    <a class="btn btn-success" href="ListNB.php">List</a>
    <br><br>
    <table class="table table-striped table-bordered">
        <tr>
            <th> ID</th>
            <th> DATE</th>
            <th> Content</th>
            <th> Update</th> 
            <th> Delete</th>

        </tr>
        <?php
        session_start();
        $user=($_SESSION['u_uid']);
        $query="SELECT * FROM `editornb` where user_uid='".$user."'";
        $result= mysqli_query($conn2, $query);
        $result_check= mysqli_num_rows ($result);
        $date=date("M/d/y");
        if ( $result_check > 0 )
        {
         while ($row= mysqli_fetch_assoc($result)){
                echo "<tr>";
                echo "<td>" .$row["entry_id"]."</td>";
                echo "<td>" .$row["date"]. "</td>";
                echo "<td>" .$row["content"]."</td>";
                echo '<td><a href="update.php?upid='.$row['entry_id'].'" type="button" class="btn btn-primary btn-sm"> 
                <span class="fa fa-edit"></span> </a></td>';

                echo '<td><a href="ListNB.php?delid='.$row['entry_id'].'" type="button" class="btn btn-danger btn-sm">
                <span class="fa fa-trash"></span> </a></td>';

                echo"</tr>";
            }
        }
        ?>

    </table>
</booy>
</html>

</div>
  • 写回答

3条回答 默认 最新

  • duanhuilao0787 2018-03-25 04:36
    关注

    mysqli_Select_db typo ?

    should be: mysqli_select_db

    Remove htmlspecialchars() in htmlspecialchars($_SERVER['PHP_SELF'])

    Just do

     $_SERVER['PHP_SELF']
    

    You are assigning $entry_id the wrong value;

    From:

    $entry_id= $row["entry_id"];
    

    To:

    $entry_id= $_GET["id"];
    

    In your second PHP file: Remove the existing session_start(); and move it at the very top of that file. You can't output anything before sending headers. It will cause error.

    <?php session_start(); ?> <-- Move it there like that. No whitespace before "<?php"
    !DOCTYPE html>
    <html>
    <head>
        <title> CK EDITOR </title>
    

    Also you have an extra space character in your <form> action attribute. In your <form> tag, the action="" attribute, Change:

    " ?id=$deluser'
    

    To:

    "?id=$deluser'
    
    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法