Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select警告:mysql_fetch_array()预计参数1是资源,空给出。
我想学习如何正确使用AJAX与PHP和MySQL。我已经看到了这个网站对于我的工作同样的例子其他人的职位,但我还没有看到我有同样的问题任何事情。
该网站保持的源代码是PHP - AJAX and PHP。
我有我的托管代码的网站是here。
第一个环节都有工作例和第二链接显示你我试图找出错误。
我试过使用mysqli,但它说了一些关于期待两个参数的内容,所以我将它改回来了。如果任何人有关于如何使其起作用的建议,我将不胜感激。
错误:mysql_fetch_array()预计参数1是资源,在/data/multiserv/users/748953/projects/1801445/www/test/getuser.php空给出上线24
的HTML代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Ajax-PHP/MySQL Cooperation Test</title>
<script type="text/javascript">
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").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("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
<select name="users" onchange="showUser(this.value)">
<option value="">Select a person:</option>
<option value="1">Peter Griffin</option>
<option value="2">Lois Griffin</option>
<option value="3">Glenn Quagmire</option>
<option value="4">Joseph Swanson</option>
</select>
</form>
<br />
<div id="txtHint">Person info will be listed here.</div>
</body>
</html>
PHP:
<?php
$q=$_GET["q"];
include("dbinfo.inc.php");
$con = mysql_connect(localhost, $username, $password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($database, $con);
$resul1 = mysql_query('SELECT * FROM `ajax_demo` WHERE id = \'\".$q.\"\'') or die(mysql_error());
echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
<th>Hometown</th>
<th>Job</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['FirstName'] . "</td>";
echo "<td>" . $row['LastName'] . "</td>";
echo "<td>" . $row['Age'] . "</td>";
echo "<td>" . $row['Hometown'] . "</td>";
echo "<td>" . $row['Job'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
难道是错字吗? $ resul1 = ...然后fetch_array($ result) – Sverker84 2012-01-10 07:35:47
请在开发中使用'error_reporting(E_ALL)',你会发现错字和undefined变量。 – 2012-01-10 07:37:49
我正在试验为什么结果没有出现,我发现这是一个建议的解决方案。这是一个错字,因为我没有改变一切,但结果仍然没有显示,我不知道为什么。感谢您指出了这一点。 – 2012-01-10 14:14:06