Php $\u get[]未定义索引
polling.phpPhp $\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
<?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仍然没有返回任何内容?