注意:未定义索引:第3行C {\ xampp \ htdocs \ img_uplod \ indexconn.php中的状态

时间:2018-04-10 06:25:26

标签: php mysql

----文件1 -----

<?php 

        $status=$_GET["status"];


        if ($status=="disp"  ) {


        $link=mysqli_connect("localhost","root","");
        mysqli_select_db($link,"ikka");
        $res=mysqli_query($link,"select * from blog");

        echo "<table>";

            while ($row=mysqli_fetch_array($res)) {
                echo "<tr>";
                echo "<td>"; echo $row["id"]; echo "</td>";
                echo "<td>"; echo $row["title"]; echo "</td>";
                echo "<td>"; echo $row["info"]; echo "</td>";

                echo "</tr>";
            }

        echo "</table>";

    }
 ?>

----文件2 ----

<div id="disp_data">


</div>



<script type="text/javascript">

    disp_data()

    function disp_data() {
      var xmlhttp=new XMLHttpRequest();
      xmlhttp.open("GET","update.php?status=disp",false);
      xmlhttp.send(null);
      document.getElementById("disp_data").innerHTML=xmlhttp.responseText;
    }

</script>

2 个答案:

答案 0 :(得分:0)

如果您要将文件1更改为

<?php 
        if (isset($_GET["status"]){

            $status=$_GET["status"];


            if ($status=="disp"  ) {


            $link=mysqli_connect("localhost","root","");
            mysqli_select_db($link,"ikka");
            $res=mysqli_query($link,"select * from blog");

            echo "<table>";

                while ($row=mysqli_fetch_array($res)) {
                    echo "<tr>";
                    echo "<td>"; echo $row["id"]; echo "</td>";
                    echo "<td>"; echo $row["title"]; echo "</td>";
                    echo "<td>"; echo $row["info"]; echo "</td>";

                    echo "</tr>";
                }

            echo "</table>";

        }
    } else {
        echo "ERROR: status variable not received";
    }
 ?>

在尝试操作状态变量之前,您将检查以确保状态变量中有值。如果没有值,您将收到显示ERROR: status variable not received

的错误消息

答案 1 :(得分:0)

在php中使用它

    <?php 
         if(!isset($_GET["status")) die("Status param error");
    ?>

或jquery,我认为你的错误是关于php的页面名称,不是update.php是 indexconn.php

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script>
       function disp_data(){
          $.get("update.php?status=disp", function(res){
             $("#disp_data").html(res);
          });
       }
    </script>