hi
i can't seem to find the part that i'm getting wrong below, but i've narrowed it down to the bit where i'm trying to pass the querystring forward in file 2
in file 2 i'm using $_GET to grab the key from file 1, echoing it as a HTML input with an id, then i'm trying to grab it in my ajax call with getdocumentbyid and placing it into the querystring to be sent off to file 3
p.s it is a simplistic RPG action of changing equipped items-
in file 1, the menu, the user's id is collected and passed onto whatever page you choose to go to
in file 2, your options are displayed ( in this case, buttons are only shown for items you own). clicking on any button will equip the item, which goes to file 3
and file 3 changes the mySQL entries affected by this change and prints a text string to say what has happened.
file1, menu
<html>
<body>
<script language="javascript" type="text/javascript">
<!--
//Browser Support Code
function battle(){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('ajaxDiv');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
var key = document.getElementById('key').value;
var queryString = "?key=" + key;
ajaxRequest.open("GET", "generator.php" + queryString, true);
ajaxRequest.send(null);
}
function market(){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('ajaxDiv');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
var key = document.getElementById('key').value;
var queryString = "?key=" + key;
ajaxRequest.open("GET", "market.php" + queryString, true);
ajaxRequest.send(null);
}
function armory(){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('ajaxDiv');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
var key = document.getElementById('key').value;
var queryString = "?key=" + key;
ajaxRequest.open("GET", "armory.php" + queryString, true);
ajaxRequest.send(null);
}
function travel(){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('ajaxDiv');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
var key = document.getElementById('key').value;
var queryString = "?key=" + key;
ajaxRequest.open("GET", "travel.php" + queryString, true);
ajaxRequest.send(null);
}
//-->
</script>
<form name='myForm'>
key: <input type='text' id='key' /> <br />
<input type='button' onclick='battle()' value='battle' />
<input type='button' onclick='market()' value='market' />
<input type='button' onclick='armory()' value='armory' />
<input type='button' onclick='travel()' value='travel' />
</form>
<div id='ajaxDiv'>result</div>
</body>
</html>
file 2- armory.php
<html>
<body>
hello
<?
$key=$_GET['key'];
echo $key;
?>
<input type="hidden" id="key" value=<?php echo $key; ?> />
<script language="javascript" type="text/javascript">
function armdagger(){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('armed');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
var key = document.getElementById('key').value;
var queryString = "?key=" + key ;
ajaxRequest.open("GET", "armdagger.php" + queryString, true);
ajaxRequest.send(null);
}
function armsabre(){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('armed');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
ajaxRequest.open("GET", "armsabre.php" , true);
ajaxRequest.send(null);
}
function armlongsword(){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('armed');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
var key = document.getElementById('key').value;
var queryString = "?key=" + key ;
ajaxRequest.open("GET", "armlongsword.php" + queryString, true);
ajaxRequest.send(null);
}
</script>
<?
$con = mysql_connect("","aqhulcus","[jedi]158");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("aqhulcus_knights", $con);
$result = mysql_query("SELECT * FROM `players` WHERE `id`='$key'")
or die(mysql_error());
$row = mysql_fetch_array( $result );
$dagger = $row['dagger'];
$sabre = $row['sabre'];
$longsword = $row['longsword'];
echo" <form name='myForm'>";
if ($dagger>0)
{echo "<input type='button' onclick='armdagger()' value='arm dagger' />";}
if ($sabre>0)
{echo "<input type='button' onclick='armsabre()' value='arm sabre' />";}
if ($longsword>0)
{echo "<input type='button' onclick='armlongsword()' value='arm longsword' />";}
echo "</form>";
mysql_close($con);
?>
<div id='armed'>result</div>
</body>
</html>
and file3, armsabre.php. armdagger and armlongsword are functionally identical
<html>
<body>
<?
$key=$_GET['key'];
$con = mysql_connect("","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("db_name", $con);
echo "sabre armed";
$result = mysql_query("UPDATE `players` SET `power` = '8' WHERE `id`='$key' ")
or die(mysql_error());
?>
</body>
</html>
also, the table being referred to by the SQL queries have a user id column, and columns that keep track of the number (int) of daggers, sabres and longswords owned.
i hope the story format helps with explaining what i'm trying to do