views:

10

answers:

1

I am learning AJAX and I am trying to recreate this fairly simple example:

http://www.w3schools.com/php/php_ajax_database.asp

I created this database:

data1

alt text

So now to recreate the example I just basically copied and pasted the code:

index.html

<html>
<head>
<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">Juan</option>
<option value="2">Manuel</option>
</select>
</form>
<br />
<div id="txtHint"><b>Person info will be listed here.</b></div>

</body>
</html>

and getuser.php

<?php
$q=$_GET["q"];

$con = mysql_connect('localhost', 'root', 'root');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("ajax_demo", $con);

$sql="SELECT * FROM user WHERE id = '".$q."'";

$result = mysql_query($sql);

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);
?>

Now the strange part is that when I go to index.html I can see the age, hometown and job but not Firstname and Lastname:

alt text

I realize this might be a very basic mistake but I cant find a workaround.

I am sorry I had to paste in so much code but I did not see any other way I could explain my problem and you could help me.

Thanks a lot in advance!

+1  A: 

You are using

FirstName  LastName

instead of

Firstname  Lastname

Array indices are case sensitive.

Pekka
OMG I´m actually hitting at my screen right know, damn php case insensitive mania. Thank you very much! Problem more that solved!!
Trufa
BTW The ice caps would have melted before I saw that mistake! Thanks again!
Trufa
@Trufa it's all right - from experience, it'll just happen once or twice, then it's stored in your instinct's memory :)
Pekka
@Pekka Hope youre right with that too! :)
Trufa