i need some advice on where im going wrong with my code its not giving me any error but its not working the way it should be. when someone types in the serach box a message title it should tell me what messages are in the database with that title but whatever i type it says "this messages is in the database. What i would like it to do would be to show measages that are in the database and then give a link to them. below is the code i have been using

<?
 
  // ajax.php

  // Get value coming from request
  $message = $_GET['message'];

  // Connect to DB
  $dbServer=mysql_connect("localhost","","");
if (!$dbServer) {echo "Failed to connect to MySQL"; exit; }
mysql_select_db("",$dbServer);  
  // Check if name exists in table
  
  if($message=="")
    echo("This message is in the database");
  else
    echo("This message is NOT in the database :(");
  
  //Close connection

?>
<HTML>
<HEAD>
<TITLE>Test Ajax</TITLE>
    <SCRIPT type="text/javascript" src="ajax.js"></SCRIPT>
  </HEAD>
  <BODY>
    search for messages: <INPUT type="text" id="message" onblur="send_request(this);">
    <DIV id="div_result"></DIV>
  </BODY>
</HTML>

i forgot to post the code to the server this is what i have please could some1 have a look an tell me where i am going wrong with this thanks.

// JavaScript Document
// ajax.js

var liveSearchReq = false;
var message = "";
	
var isIE = false;
// on !IE we only have to initialize it once
if (window.XMLHttpRequest)
{
	liveSearchReq = new XMLHttpRequest();
}

// +----------------------------------------------------------------------+
// | Init HTTP object
// +----------------------------------------------------------------------+
function initliveSearchReq()
{
  if(window.XMLHttpRequest)
  {
    // Firefox et autres
  	liveSearchReq = new XMLHttpRequest();
  } 
  else if(window.ActiveXObject)
  {
    // Internet Explorer 
  	try
    {
  		liveSearchReq = new ActiveXObject("Msxml2.XMLHTTP");
  	}
    catch (e)
    {
      liveSearchReq = new ActiveXObject("Microsoft.XMLHTTP");
  	}
  } 
}
// +----------------------------------------------------------------------+
// | Send request
// +----------------------------------------------------------------------+
function send_request(t)
{
  // Get user input
  message = t.value;
  if(message!="")
  {
    // Create HTTP object
    initliveSearchReq();
  	
  	// Set function to handle response
  	liveSearchReq.onreadystatechange= DisplayResult;
  	
  	// Send request
  	liveSearchReq.open("GET", "ajax.php?message=" + message);
  	
    // Finish transaction
  	liveSearchReq.send(null);
  }
  else
  {
	  var  sh = document.getElementById("div_result");
	  sh.innerHTML = "Please enter value";    
  }
}
// +----------------------------------------------------------------------+
// | Handle response
// +----------------------------------------------------------------------+
function DisplayResult()
{
	if (liveSearchReq.readyState == 4)
  {
		var  sh = document.getElementById("div_result");
		sh.innerHTML = liveSearchReq.responseText;
	}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.