Jump to content


This topic is now archived and is closed to further replies.


php/mysql form help

Recommended Posts

[a href=\"http://www.webpasties.com/xmlHttpRequest/\" target=\"_blank\"]http://www.webpasties.com/xmlHttpRequest/[/a]

I have used the above tutorial using my own database and form but I am having a slight problem. which when I run the script:
I get correct results:
<?xml version="1.0" standalone="yes" ?>
- <activity_id>

however when I type id= 6 in the form It wont fill in itself but when I double click on text boxes I get a list to select the full_name and account_no.

I have checked the form many times and couldnt find any problems. Could someone plz have a look at the code below help me.

if anyone think of a better to way than plz let me know. All I want is when user enters the postcode/ id the full address shows (saved in mysql) in a textbox to make sure that the correct post code is entered.

I posted the same problem in a newbie section aswell so sorry if you get see the same problem again.

Here is the form.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >


<title>ZIP Code to City and State using XmlHttpRequest</title>

<script language="javascript" type="text/javascript">

var url = "getCityState.php?param="; // The server-side script

function handleHttpResponse() {

if (http.readyState == 4) {

if (http.responseText.indexOf('invalid') == -1) {

// Split the comma delimited response into an array

// Use the XML DOM to unpack the city and state data

var xmlDocument = http.responseXML;

var full_name = xmlDocument.getElementsByTagName('full_name').item(0).firstChild.data;

var account_no = xmlDocument.getElementsByTagName('account_no').item(0).firstChild.data;

document.getElementById('full_name').value = full_name;

document.getElementById('account_no').value = account_no;

isWorking = false;




var isWorking = false;

function updateCityState() {

if (!isWorking && http) {

var activity_idValue = document.getElementById("activity_id").value;

http.open("GET", url + escape(activity_idValue), true);

http.onreadystatechange = handleHttpResponse;

isWorking = true;




function getHTTPObject() {

var xmlhttp;


@if (@_jscript_version >= 5)

try {

xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

} catch (e) {

try {

xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

} catch (E) {

xmlhttp = false;




xmlhttp = false;

@end @*/

if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {

try {

xmlhttp = new XMLHttpRequest();

} catch (e) {

xmlhttp = false;



return xmlhttp;


var http = getHTTPObject(); // We create the HTTP Object




<form action="GET">



<input type="text" size="5" name="activity_id" id="activity_id" onblur="updateCityState();" />


Full Name:

<input type="text" name="full_name" id="full_name" />

Account No:

<input type="text" size="2" name="account_no" id="account_no" />




* Connects to the database.
* Return false if connection failed.
* Be sure to change the $database_name. $database_username , and
* $database_password values to reflect your database settings.
function db_connect() {
$database_name = 'rep'; // Set this to your Database Name
$database_username = ''; // Set this to your MySQL username
$database_password = ''; // Set this to your MySQL password
$result = mysql_pconnect('localhost',$database_username, $database_password);
if (!$result) return false;
if (!mysql_select_db($database_name)) return false;
return $result;
$conn = db_connect(); // Connect to database
if ($conn) {
$activity_id = $_GET['param']; // The parameter passed to us
$query = "select * from repactivity where activity_id = '$activity_id'";
$result = mysql_query($query,$conn);
$count = mysql_num_rows($result);
if ($count > 0) {
$full_name = mysql_result($result,0,'full_name');
$account_no = mysql_result($result,0,'account_no');
if (isset($full_name) && isset($account_no)) {
// $return_value = $full_name . "," . $account_no;
$return_value = '<?xml version="1.0" standalone="yes"?><activity_id><full_name>'.$full_name.'</full_name><account_no>'.$account_no.'</account_no></activity_id>';
else {
$return_value = "invalid".",".$_GET['param']; // Include Zip for debugging purposes
header('Content-Type: text/xml');
echo $return_value; // This will become the response value for the XMLHttpRequest object

Share this post

Link to post
Share on other sites


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.