Jump to content

PHP + AJAX + MySQL: Information Bar (The issue is with AJAX)


maxudaskin

Recommended Posts

Hi Guys!

I'm working on a website feature that will grab information about a selected airport from a MySQL database. The information will be grabbed and displayed, assuming that the airport identification is correct, to the screen, although I am having some troubles here. The code is below.

 

Excerpt from front end

<div class="contentBox cb_blue mar_bottom">
<input type="text" name="departure" id="departure" style="width:350px;" onChange="loadAirportInfo('departureInfo', 'this.value')" value="<?= @$_POST['departure']; ?>">
<div id="departureInfo"></div>
</div>

 

loadAirportInfo code

function loadAirportInfo(elemId, ident)
{
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(elemId).innerHTML=xmlhttp.responseText;
   }
  }
xmlhttp.open("GET","include/lib/ajaxAddInfo.php?get=airportInfo&airport="+ident,true);
xmlhttp.send();
}

 

ajaxAddInfo.php code

<?php
if($_GET['get'] == 'airportInfo') {
$sql = 'SELECT * FROM `geo_airports` WHERE `ident` = \'' . $_GET['ident'] . '\'';
$query = mysql_query($sql);
if(mysql_num_rows($query) < 1) {
	return '';
} else {
	$result = mysql_fetch_array($query);
	return	'Identification: '	. $result['ident'] . '<br />' .
			'Airport Name: '	. $result['name'] . '<br />' .
			'Municipality: '	. $result['municipality'] . '<br />' .
			'Country: '			. $result['country'] . '<br />';
}
}
?>

 

Now, I am sure that the issue is with the AJAX and not the PHP or regular Javascript.

 

Thank you for your help and opinions in advance. :)

 

Max

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.