我创建了proba.html文件,getuser.php,名为'mobilni'的数据库,以及名为'imena'的表。代码出了什么问题,它没有显示表中的结果,只有空白?
proba.html代码:
<script>
function showUser(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
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("txtHint").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
}
</script>
<form>
<select name="okrug" onchange="showUser(this.value)">
<option value="">Okrug:</option>
<option value="Raski">Raski</option>
<option value="Banatski">Banatski</option>
<option value="Backi">Backi</option>
<option value="Beogradski">Beogradski</option>
</select>
</form>
<br>
<div id="txtHint"><b>Person info will be listed here...</b></div>
getuser.php代码:
<?php
$q = intval($_GET['q']);
$con = mysqli_connect('localhost','root','','mobilni');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"mobilni");
$sql="SELECT * FROM imena WHERE Okrug = '".$q."'";
$result = mysqli_query($con,$sql);
echo "<table>
<tr>
<th>Ime</th>
<th>Okrug</th>
<th>Telefon</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['Ime'] . "</td>";
echo "<td>" . $row['Okrug'] . "</td>";
echo "<td>" . $row['Telefon'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
答案 0 :(得分:0)
而不是
$q = intval($_GET['q']);
试试这个:
$q = $_GET['q'];
看,如果有帮助。