Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php $\u get[]未定义索引_Php_Get - Fatal编程技术网

Php $\u get[]未定义索引

Php $\u get[]未定义索引,php,get,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['u

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

index.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";
?>
<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>

函数轮询(){
var-xmlHttp;
if(window.XMLHttpRequest){
xmlHttp=新的XMLHttpRequest();
}否则{
xmlHttp=新的ActiveXObject(“Microsoft.xmlHttp”);
}
xmlHttp.onreadystatechange=函数(){
if(xmlHttp.status==200&&xmlHttp.readyState==4){
var result=xmlHttp.responseText;
如果(结果='true'){
window.location.href='welcome.php';
}
}
}
//var randnumber=document.getElementById(“randnumber”).value;
randnumber=“12345687”;
**open(“GET”,“polling.php?randnumber=“+randnumber,true”)**
xmlHttp.send();
}
setInterval(“polling()”,1000)
问题是

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

$randnumber1=$\u获取['randnumber']
我不明白为什么它甚至不能
回显“$randnumber”
? 如何使用
$\u get[]
获取
randnumber

谢谢,我是新来的

作为更好的练习,您应该始终使用如下语法

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

这将始终防止您出现未定义的错误,并不断告诉您是否正在获取值。

您也应该完全阅读这篇文章,尝试打印
$randnumber1=$\u GET['randnumber']
在这一行之前
print\r($\u GET)
您在哪里/如何看到错误?我尝试了您的代码,我能够将我的数字输入到PHP,然后发出
echo
警报。谢谢。我已经对此进行了测试。它可以帮助避免警告。但是$randNo仍然没有返回任何内容?