Hi guys,
I need to put data that i get it from db2 and display it into each text boxes (Name, Address and Postcode). What i got now, its displayed Name's data that i got from db2 into all text boxes (Name, Address and Postcode) . All i want is each data for each text box.
Here is my code :
//html
<tr>
<td height="25" align="right">Id Num <font color="#FF0000">*</font></td>
<td height="25" align="center">:</td>
<td height="25"><input name="id_num" type="text" id="id_num" size="12" maxlength="12" onKeyUp="checkInput(this.value, 'ajaxChecker-name.php');" value="<?php echo $selected_id_Num; ?>"/>
</td>
</tr>
<tr>
<td height="25" align="right">Name </td>
<td height="25" align="center">:</td>
<td height="25"><input type="text" name="name" id="name" size="30" maxlength="50"></td>
</tr>
<tr>
<td height="25" align="right">Address </td>
<td height="25" align="center">:</td>
<td height="25"><input type="text" name="address" id="address" size="30" maxlength="50" ></td>
</tr>
<tr>
<td height="25" align="right">Postcode </td>
<td height="25" align="center">:</td>
<td height="25"><input type="text" name="postcode" id="postcode" size="30" maxlength="50"></td>
</tr>
//checkInput.js
var xmlhttp
function checkInput(str, checker_file){
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null){
alert ("Your browser does not support AJAX!");
return;
}
var url=checker_file;
url=url+"?query="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
function stateChanged(){
if (xmlhttp.readyState==4){
document.getElementById("name").value=xmlhttp.responseText;
document.getElementById("address").value=xmlhttp.responseText;
document.getElementById("postcode").value=xmlhttp.responseText;
}
}
}
function GetXmlHttpObject(){
if (window.XMLHttpRequest){
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject){
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
//ajaxChecker-name.php
include('include/connect_db.php');
$id_num = $_REQUEST["query"];
$host = "xx";
$user = "xx";
$pass = "xx";
$db2connect = db2_connect($host, $user, $pass);
$check_Id_Num = "
SELECT
COUNT(ID_NUM) AS HIT
FROM
DB_NAME
WHERE
ID_NUM = '$id_num'
";
$result_Id_Num = db2_exec($db2connect, $check_Id_Num);
$row_result = db2_fetch_array($result_Id_Num);
$hit_Id_Num = $row_result['0'];
if($hit_Id_Num == true){
$checkIdNum = "SELECT
NAME,
ADD,
POSTCODE
FROM
DB_NAME
WHERE
ID_NUM = '$id_num'";
$resultIdNum = db2_exec($db2connect, $checkIdNum);
$row_result = db2_fetch_array($resultIdNum);
echo $name = $row_result['0'];
echo $add = $row_result['1'];
echo $postcode = $row_result['2'];
}else
{
echo "Id Num Not Valid";
}
Any suggestion guys?