-2

---- file 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>";

    }
 ?>

---- file 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>

B. Desai
  • 16,414
  • 5
  • 26
  • 47
  • 1
    mention your file name instead of file 1 and file 2 – PHP dev Apr 10 '18 at 06:30
  • You're assuming `$_GET["status"]` is always set. Looks like it isn't. – brombeer Apr 10 '18 at 06:39
  • 1
    Possible duplicate of [PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset"](https://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef) – Nigel Ren Apr 10 '18 at 06:51

2 Answers2

0

if you were to change file 1 to

<?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";
    }
 ?>

You would be checking to make sure there is a value in the status variable before trying to manipulate it. If there is no value you would get the error message reading ERROR: status variable not received

Lordbug
  • 119
  • 1
  • 10
0

use this in php

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

or jquery, i think that your error is about php page name, is not update.php is 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>
Watash1
  • 320
  • 4
  • 7