NSA
sudo apt-get thefuckout.tar.gz
- Dec 9, 2011
- 715
- 86
Hello all,
I am learning Ajax and started to build up a file.
Now when a user types a name into a textbox it will kick off the Ajax which will send a connection over to PHP which will then send a query to a database to then return some results. (I think I said that right).
Now when the user clicks the button this Ajax occurs:
Which will then kick this PHP off:
But, I keep getting "undefined" returned... can anyone tell me why?
Thanks.
I am learning Ajax and started to build up a file.
Now when a user types a name into a textbox it will kick off the Ajax which will send a connection over to PHP which will then send a query to a database to then return some results. (I think I said that right).
Now when the user clicks the button this Ajax occurs:
HTML:
var xmlhttp;
var url;
function ajaxFunction() {
if(window.ActiveXOject) {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}else{
alert("This page requires an updated browser.");
}
}
function getInfo() {
ajaxFunction();
var entryInfo = document.getElementById("entry").value;
function stateChanged(){
if(xmlhttp.readyState == 4){
document.getElementById("results").innerHTML = xmlhttp.respnseText;
}
}
url = "info.php?user="+entryInfo;
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
Which will then kick this PHP off:
Code:
<?php
$connection = mysql_connect("localhost","root",""); or
die("Did not connect to database");
mysql_select_db("people") or die ("No database found");
if(isset($_GET['user'])) {
$name = $_GET['user'];
$query = mysql_query("select * from info where name='$name' limit 1");
$num_rows = mysql_num_rows($query);
if($num_rows == 1){
$row = mysql_fetch_assoc($query);
$info = "
Name = ".$row['name']."<br>
Address = ".$row['address']."<br>
Post Code = ".$row['postcode']."<br>
Telephone = ".$row['telephone']."<br>
";
}else{
$info = "No users found";
}
}else{
$info = "No records found";
}
echo $info;
?>
But, I keep getting "undefined" returned... can anyone tell me why?
Thanks.