Sunday, 8 September 2013

using php to call mysql databases

using php to call mysql databases

I have built a table in mysql and
I am trying to call the attributes and properties of a particular field!
Here's the link to my mockup site -
http://smartliving.netai.net/example2.html
This is for a company project that I am doing right now!
I got a drop down menu - if I pick a Name I am supposed to get the
properties and attribute... This is the error message that I get! PLEASE
HELP ME OUT ASAP!!!
Firstname Lastname Age Hometown Job PHP Error Message
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result,
boolean given in /home/a6676729/public_html/getuser.php on line 24
Here's the HTML page -
<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">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"><b>Person info will be listed here.</b></div>
</body>
</html>
Here's the PHP page! Getuser.php is the file name - Line 24 - what is
wrong about this line of code - while($row = mysqli_fetch_array($result)){
?
<?php
$q = intval($_GET['q']);
$con = mysqli_connect("mysql13.000webhost.com",
"a6676729_smart","semen19*","a6676729_smart.my_db");
if (!$con)
{
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"ajax_demo");
$sql="SELECT * FROM user WHERE id = '".$q."'";
$result = mysqli_query($con,$sql);
echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
<th>Hometown</th>
<th>Job</th>
</tr>";
while($row = mysqli_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>";
mysqli_close($con);
?>
here are images of my datatable from the phpMyAdmin menus -
http://s2.postimg.org/sozbodzg9/Screen_Shot001.png
hs11dotpostimgdotorg/qsb5bfeyb/Screen_Shot002dotpng
and s7dotpostimgdotorg / c4qmyhl8b / Screen_Shot003dotpng (system is not
allowing me to post more than 2 links - please replace dot with a real dot
. !)
Please help me out - i need to get this done ASAP!!!
how do I get the attributes of a user/id get picked printed on the screen
right away!!!
Thanks a lot!

No comments:

Post a Comment