我进行了测试,并确认我能够通过提醒函数 checkusername 中的值来从输入框中获取值。我还为查询单独测试了 php 文件,并且它有效。我真的认为问题是将值从我的第一个页面转移到另一个页面(thoughtverifier.php)或从“thoughtverifier.php”获取值
<script>
function checkusername(puser){
var AJAXObject;
if (puser == "" )
return ;
if (window.XMLHttpRequest)
AJAXObject =new XMLHttpRequest();
else
AJAXObject =new ActiveXObject("Microsoft.XMLHttp");
AJAXObject.onreadystatechange= function(){
if (AJAXObject.readyState ==4 && AJAXObject.status == 200) {
document.getElementById('txtuser').innerHTML=AJAXObject.responseText
}
AJAXObject.open("GET","thoughtverifier.php?puse="+puser,true);
AJAXObject.send();
}
</script>
和 HTML 代码-
<Form method ="post" name="regform" id ="regform" action="thoughtshomepage.php">
<table class="alligm">
<tr>
<td>Username</td>
<td><input type="text" name="txtuser" onchange="checkusername(this.value)"></td>
</tr>
</table>
</Form>
和涉及的 PHP - 我正确连接到我的 SQL 和其余的
$q = $_GET['puse'];//i have doubt here
$strSQL =" SELECT * FROM `tableuser` WHERE username = '$q'" ;
mysqli_query($con,$strSQL) or die(mysqli_error($con));
$result = mysqli_query($con,$strSQL);
$rowcount=mysqli_num_rows($result);
if ($rowcount > 0) {
echo "user exists";
}
else {
echo "no";
}
mysqli_close($con);
?>
偶然的你
隔江千里
开满天机