$ _get []未定义的索引

时间:2017-09-28 05:26:04

标签: php get

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>

问题是那个

  

未定义的索引:polling.php中的randnumber

<{1>} $randnumber1 = $_GET['randnumber']; 我不明白为什么它甚至不能echo "$randnumber"? 如何使用randnumber获取$_GET[]? 谢谢你,我是新人。

1 个答案:

答案 0 :(得分:0)

作为一种更好的做法,您应该始终使用如下语法

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

这将始终阻止您处理未定义的错误并不断告诉您是否正在获取值。