-1

polling.php

<?php
require 'mysql_connect.php';

$randnumber1 = $_GET['randnumber'];


echo "$randnumber1";

$result = mysqli_query($con, "select * from login_rocord where randnumber='$randnumber1'");
$row = mysqli_fetch_array($result);
if ($row['username'] != "")
    echo "true";
else
    echo "false";
?>

index.php

<script>
    function polling() {

        var xmlHttp;
        if (window.XMLHttpRequest) {
            xmlHttp = new XMLHttpRequest();
        } else {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlHttp.onreadystatechange = function () {
            if (xmlHttp.status == 200 && xmlHttp.readyState == 4) {
                var result = xmlHttp.responseText;
                if (result == 'true') {
                    window.location.href = 'welcome.php';
                }
            }
        }

        //var randnumber = document.getElementById("randnumber").value;
        randnumber = "12345687";
        ** xmlHttp.open("GET", "polling.php?randnumber=" + randnumber, true); **
                xmlHttp.send();
    }
    setInterval("polling()", 1000)

</script>

And the question is that

Undefined index: randnumber in polling.php

on $randnumber1 = $_GET['randnumber']; I don't understand that why it even can't echo "$randnumber"? How could I get the randnumber by using $_GET[]? Thankyou,I'm a newcomer.

B. Desai
  • 16,414
  • 5
  • 26
  • 47
CXQ
  • 1

1 Answers1

0

As a better practise you should always use syntax like below

$randNo = isset($_GET['randnumber'])?$_GET['randnumber']:"";
echo $randNo;

This will always prevent you from undefined errors and keeps telling you that you are getting values or not.

BeingExpert
  • 523
  • 1
  • 5
  • 16
  • 1
    Thank you.I have test this.It can help avoid the warning.But the $randNo still return nothing? – CXQ Sep 28 '17 at 06:31