To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
I'm tring to create a lookup via PHP AJAX. I keep getting the following error message, can any1 help me please.
"
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /test/getuser.php on line 25
"
I have 2 files and 1 mysql database.
Index.html File
Code:
<html>
<head>
<script type="text/javascript">
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
document.write(str);
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="make" onchange="showUser(this.value)">
<option value="">Select a Vehicle:</option>
<option value="1">Acura</option>
<option value="2">Alfa Romeo</option>
<option value="3">Aston Martin</option>
<option value="4">Honda</option>
</select>
</form>
<br />
<div id="txtHint"><b>Vehicle info will be listed here.</b></div>
</body>
</html>
When posting PHP code, please use the board's [php]..[/php] bbcode tags as they make your code much easier to read and analyze.
As for your issue, you need to debug the SQL errors that are occurring. If mysql_query() returns boolean FALSE for a SELECT query, then you need to examine the SQL error message (using mysql_error(), for example) to find the cause of the problem.
Also, user-supplied data should never be placed directly into a SQL query string else your code will be vulnerable to SQL injection attacks and/or just plain SQL errors. Instead, you must first sanitize it with a function such as mysql_real_escape_string() (for string data).
__________________
***If your problem has been solved, PLEASE click the RESOLVED LINK under "Thread Tools"***
"Well Bones, do the new medical facilities meet with your approval?" -- Kirk
"They do not. It's like working in a damn computer center" -- McCoy (Star Trek: TMP)