Jump to content

[SOLVED] Query and Display


Eggzorcist

Recommended Posts

I'm trying to make a form which will using ajax get information through php and sql and will display that information Ajax style but I'm currently getting an error.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<LINK REL=stylesheet HREF="stylesheet.css" TYPE="text/css">
</head>

<body>


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

<!-- 
//Browser Support Code
function ajaxFunction(){
var ajaxRequest;  
try{
	ajaxRequest = new XMLHttpRequest();
} catch (e){

	try{
		ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try{
			ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");

		} catch (e){

			alert("Your browser broke!");
			return false;
		}
	}
}

ajaxRequest.onreadystatechange = function(){
	if(ajaxRequest.readyState == 1){
		document.myForm.time.value = ajaxRequest.responseText;
	}
}
var id = document.getElementById('id').value;
var queryString = "?id=" + id;
ajaxRequest.open("GET", "trackeractions.php" + queryString, true);
ajaxRequest.send(null); 


}

//-->
</script>


<div class='wrap'>
<p><img src="images/logo.png" width="190" height="29" /><br />
</p>
<div class="nav">Home</div>
<div class="nav2">Services</div>
<div class="nav2">About Us</div>
<div class="nav2">Customer Support</div>
<div class="nav2">Tracker</div>
<div class="spacer"></div>
<div class="title">
  <div class="textle">Price & Services </div>
</div>
<div class='picture'><img src="images/cargo.png" alt="cargoplane" width="450" height="199" /></div>

<div class='content'>

Package ID:<input name="id" type="text" value="" size="10" maxlength="10" /> <br />
<input type='button' onclick='ajaxFunction()' value='Track' />

</div>


</div>
</body>
</html>

 

php file

 

<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "tgj4u";
//Connect to MySQL Server
mysql_connect($dbhost, $dbuser, $dbpass);
//Select Database
mysql_select_db($dbname) or die(mysql_error());
// Retrieve data from Query String
$id = $_GET['id'];
// Escape User Input to help prevent SQL Injection
$id = mysql_real_escape_string($id);
//build query
$query = "SELECT * FROM maildata WHERE id = '$id'";

//Execute query
$qry_result = mysql_query($query) or die(mysql_error());

// Insert a new row in the table for each person returned
$info = mysql_fetch_array($qry_result)

echo "Sent by: " . $info['sender'] . "<br>";	
echo "Recipient: " . $info['recipient'] . "<br>";	
echo "Departed: " . $info['depart'] . "<br>";
echo "Satus: " . $info['depart']; . "<br>";
echo "Current Location: " . $info['currentlocation'] . "<br>";
echo "Arrival Location: " . $info['finallocation'] . "<br>";
echo "Expected on: " . $info['expected'] . "<br>";


?>

 

I've tried alot of things, but I dont see where the error is...

 

 

Thanks

Link to comment
Share on other sites

I don't get any visual error but when I click submit it does "error on page" at the bottom info of the browser where it normally says the status of that loads the page or "done" status.

 

 

The PHP does not yet work fully independantly, however, it does show information independantly just not the query information but everything else does.

Link to comment
Share on other sites

Yup.

 

Wrap your form elements inside <form> tags. And get a js debugging tool so you can track the javascript errors easier or when you can't figure it out you can post the js error so someone can help you easier

 

https://addons.mozilla.org/nl/firefox/addon/1843 webdeveloper toolbar

https://addons.mozilla.org/en-US/firefox/addon/60 firebug

 

the error you are getting now is a different one

Link to comment
Share on other sites

Hmmm sort of have to eat my own words but anyway

 

see the following?

document.myForm.time.value = ajaxRequest.responseText;

thats where the received text gets placed on your page

change that to something like:

document.getElementById('your_div').innerHTML = ajaxRequest.responseText;

then add a div element to your page

<div id="your_div"><div>

Link to comment
Share on other sites

I downloaded firebug but coudnt seem to find the mistake.

 

So far all its doing is refreshing the page and adding the ?id=55583&ID=Track to the url

 

I'm unsure why ID=Track and I am not seeing any echo thats within my php document for some reason.

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.