Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.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/8/mysql/69.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文件从html表单[AJAX]接收空白值_Php_Mysql_Ajax_Xampp - Fatal编程技术网

PHP文件从html表单[AJAX]接收空白值

PHP文件从html表单[AJAX]接收空白值,php,mysql,ajax,xampp,Php,Mysql,Ajax,Xampp,我的目标是使用AJAX,但我在这方面有点新手,让用户有可能搜索一些东西并获取关于这些内容的数据库行。我测试了好几次,试着调试,却找不到解决方法。谢谢 HTML代码: <!DOCTYPE html> <html> <head> <script> function showUser(str) { if (str=="") { document.getElementById("jotamacho").innerHTML=""; return; } if

我的目标是使用AJAX,但我在这方面有点新手,让用户有可能搜索一些东西并获取关于这些内容的数据库行。我测试了好几次,试着调试,却找不到解决方法。谢谢

HTML代码:

<!DOCTYPE html>
<html>
<head>
<script>
function showUser(str) {
if (str=="") {
document.getElementById("jotamacho").innerHTML="";
return;
} 
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("jotamacho").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("POST","output.php",true);
xmlhttp.send();
}
</script>


</head>

<body>

<form action="output.php" method="post"  onchange="showUser(this.value)">
<select name="feature">
<option value="Nome">Primeiro Nome</option>
<option value="Apelido">Apelido</option>
<option value="País">País de origem</option>
<option value="Data">Data de nascimento</option>
</select>


Search: <input type="text" name="textquery" onchange="showUser(this.value)><br>


<br>
<div id="jotamacho">Here !</div>  

</form>
</body>
</html>
<?php

$con=mysqli_connect("127.0.0.1","root","","");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$search =mysqli_real_escape_string($con, $_POST['textquery']);
$coluna =mysqli_real_escape_string($con, $_POST['feature']);
$resposta = mysqli_query($con,"SELECT Nome,Apelido,Data_nascimento,País FROM Pessoa   WHERE Pessoa.$coluna like '$search' ");

echo " <b> Results:";

echo "<table border='5'>
<tr>
<th>Nome</th>
<th>Apelido</th>
<th>Data de Nascimento</th>
<th>País</th>
</tr>";


while($row = mysqli_fetch_array($resposta)) { 
echo "<tr>";
echo "<td>" . $row['Nome'] . "</td>";
echo "<td>" . $row['Apelido'] . "</td>";
echo "<td>" . $row['Data_nascimento'] . "</td>";
echo "<td>" . $row['País'] . "</td>";
echo "</tr>";
}

echo "</table>";

mysqli_close($con);
?>

函数showUser(str){
如果(str==“”){
document.getElementById(“jotamacho”).innerHTML=“”;
返回;
} 
if(window.XMLHttpRequest){
//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}else{//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数(){
if(xmlhttp.readyState==4&&xmlhttp.status==200){
document.getElementById(“jotamacho”).innerHTML=xmlhttp.responseText;
}
}
open(“POST”,“output.php”,true);
xmlhttp.send();
}
Primeiro Nome
阿皮利多
原汁原味
纳西门托数据
搜索:

函数showUser(){
如果(window.XMLHttpRequest){
//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}else{//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}            
xmlhttp.onreadystatechange=函数(){
如果(xmlhttp.status==200){
document.getElementById(“jotamacho”).innerHTML=xmlhttp.responseText;
}            
}            
var fea=document.getElementById(“功能”).value;
var txq=document.getElementById(“textquery”).value;
open(“POST”,“output.php”,true);
setRequestHeader(“内容类型”,“应用程序/x-www-form-urlencoded”);
xmlhttp.send(“feature=“+fea+”&textquery=“+txq”);
}            
Primeiro Nome
阿皮利多
原汁原味
纳西门托数据
搜索:

在这里
仍然是空变量:/notices不见了!但是当我插入文本时,没有显示任何数据库行:/啊,对不起,佩斯奎萨是从翻译过来的,当我在葡萄牙语中使用post-xD的意思是“搜索”:P。
<!DOCTYPE html>            
<html>            
<head>            
<script>            
function showUser() {            
if (window.XMLHttpRequest) {            
// code for IE7+, Firefox, Chrome, Opera, Safari            
xmlhttp=new XMLHttpRequest();            
} else { // code for IE6, IE5            
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");            
}            
xmlhttp.onreadystatechange=function() {            
if (xmlhttp.status==200) {            
document.getElementById("jotamacho").innerHTML=xmlhttp.responseText;            
}            
}            
var fea=document.getElementById("feature").value;            
var txq=document.getElementById("textquery").value;            
xmlhttp.open("POST","output.php",true);            
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");            
xmlhttp.send("feature=" + fea + "&textquery=" + txq);            
}            
</script>            


</head>            
<body>            
<select id="feature">            
<option value="Nome">Primeiro Nome</option>            
<option value="Apelido">Apelido</option>            
<option value="País">País de origem</option>            
<option value="Data">Data de nascimento</option>            
</select>            
Search: <input type="text" id="textquery" onchange="showUser()"><br>            
<br>            
<div id="jotamacho">Here !</div>              
</body>            
</html>