I have a form with drop-down options, when the user selects an option AJAX should dynamically update the page with data from my MySQL database using PHP.
The page with the form on can be found here.
Selecting an option you can see the current error messages.
The database is called "products" and the table within the database which I'm trying to access is called "deepblack"
Database:
id,width,length,price
1,2,5,12
2,2,10,20
3,3,5,18
4,3,10,30
5,4,5,24
6,4,10,40
The Markup:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script>
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">2-5</option>
<option value="2">2-10</option>
<option value="3">3-5</option>
<option value="4">3-10</option>
<option value="5">4-5</option>
<option value="6">4-10</option>
</select>
</form>
<br>
<div id="txtHint"><b>Person info will be listed here.</b></div>
</body>
</html>
PHP - getuser.php
<?php
$q = intval($_GET['q']);
$con = mysql_connect('cust-mysql-123-17','products','abc123','products');
if (!$con)
{
die('Could not connect: ' . mysql_error($con));
}
mysql_select_db($con,"products");
$sql="SELECT * FROM user WHERE id = '".$q."'";
$result = mysql_query($con,$sql);
echo "<table border='1'>
<tr>
<th>id</th>
<th>width</th>
<th>length</th>
<th>price</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['width'] . "</td>";
echo "<td>" . $row['length'] . "</td>";
echo "<td>" . $row['price'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
Does anyone know why I am getting these error messages and what needs to be changed?
Thanks