Jump to content

[SOLVED] Php and Ajax Train Page, help plz.


Dethman

Recommended Posts

This script is supposed to Train Troops for an army based MMORPG.

 

Train Page:

 

      <TABLE width="100%">
        <TBODY>
        <TR>
          <TD style="PADDING-RIGHT: 25px" vAlign=top width="50%">
            <TABLE id="UserInfo" style="background:#000000;" class=table_lines cellSpacing=0 cellPadding=6 width="100%" 
            border=0>
              <TBODY>
              <TR>
                <TH class="subhr" colSpan=2>Personnel</TH></TR>
              <TR>
                <TD><B>Trained Attack Soldiers</B></TD>
                <TD align=right><? numecho ($user->trainedAttackSold)?></TD></TR>
              <TR>
                <TD><B>Trained Attack Mercenaries</B></TD>
                <TD align=right><? numecho ($user->trainedAttackMerc)?></TD></TR>
              <TR>
                <TD><B>Trained Defense Soldiers</B></TD>
                <TD align=right><? numecho ($user->trainedDefSold)?></TD></TR>
              <TR>
                <TD><B>Trained Defense Mercenaries</B></TD>
                <TD align=right><? numecho ($user->trainedDefMerc) ?></TD></TR>
              <TR>
                <TD><B>Untrained Soldiers</B></TD>
                <TD align=right><? numecho ($user->untrainedSold) ?></TD></TR>
              <TR>
                <TD><B>Untrained Mercenaries</B></TD>
                <TD align=right><? numecho ($user->untrainedMerc) ?></TD></TR>
              <TR>
                <TD class=subh><B>Spies</B></TD>
                <TD class=subh align=right><? numecho ($user->spies) ?></TD></TR>
              <TR>
                <TD><B>Total Fighting Force</B></TD>
                <TD align=right><? numecho (getTotalFightingForce($user))?></TD></TR></TBODY></TABLE><BR></TD>
          <TD vAlign=top width="50%">

            <TABLE class=table_lines id="UserInfo" style="background:#000000;" cellSpacing=0 cellPadding=6 width="100%" 
            border=0>
              <TBODY>
              <TR>
                <TH class="subhr" align=middle colSpan=3>Train Your Troops</TH></TR>
              <TR>
                <TH class="subhr" align=left>Training Program</TH>
                <TH class="subhr" align=right>Cost Per Unit</TH>
                <TH class="subhr">Quantity</TH></TR>
              <TR>
                <TD>Attack Specialist</TD>
                <TD align=right>2,000 Plasma</TD>
                <TD align=middle><INPUT size=5 value=0 
              name=atsold id="atsold"></TD></TR>
              <TR>
                <TD>Defense Specialist</TD>
                <TD align=right>2,000 Plasma</TD>
                <TD align=middle><INPUT size=5 value=0 
              name=defsold id="defsold"></TD></TR>
              <TR>
                <TD>Spy</TD>
                <TD align=right>3,500 Plasma</TD>
                <TD align=middle><INPUT size=5 value=0 name=spy id="spy"></TD></TR>
              <TR>
                <TD>Reassign Attack Specialist</TD>
                <TD align=right>0 Plasma</TD>
                <TD align=middle><INPUT size=5 value=0 
                name=reat id="reat"></TD></TR>
              <TR>
                <TD>Reassign Defense Specialist</TD>
                <TD align=right>0 Plasma</TD>
                <TD align=middle><INPUT size=5 value=0 
                name=redef id="redef"></TD></TR>
              <TR>
                <TD align=middle colSpan=3 align="center">	<div id="respondeID"></div>
			<input type="hidden" id="plasma" value="56000000">
			<input type="hidden" id="tritainium" value="45000000">
<a href="javascript:trainTroops();" class="tooltip" title="Here you can buy a flagship in which you can upgrade and use in a lengthy battle.">Train Troops</a>
              </TD></TR></TBODY></TABLE><BR></TD></TR>

 

Train ajax Included Header File:

 


function getXMLHttp()
{
  var xmlHttp

  try
  {
    //Firefox, Opera 8.0+, Safari
    xmlHttp = new XMLHttpRequest();
  }
  catch(e)
  {
    //Internet Explorer
    try
    {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
      try
      {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch(e)
      {
        alert("Your browser does not support AJAX!")
        return false;
      }
    }
  }
  return xmlHttp;
}

function trainTroops()
{
  var xmlHttp = getXMLHttp();
  
  xmlHttp.onreadystatechange = function()
  {
    if(xmlHttp.readyState == 4)
    {
      HandleResponseTrain(xmlHttp.responseText);
    }
  }
   
   var atsold = document.getElementById("atsold").value;
   var defsold = document.getElementById("defsold").value;
   var spy = document.getElementById("spy").value;
   var reat = document.getElementById("reat").value;
   var redef = document.getElementById("redef").value; 

  xmlHttp.open("GET", "train2.php?&atsold=" + atsold + "&defsold=" + defsold + "&spy= " + spy + "&reat= " + reat + "&redef= " + redef, true);
  xmlHttp.send(null);
}

function HandleResponseTrain(response)
{

  document.getElementById('respondeID').innerHTML = response;
  
}

 

Php File train2.php:

 

<?php
include "../vsys.php";


$user=getUserDetails($_SESSION['isLogined'],"*");

if($_GET['train']){

	if($_GET['atsold']){
		$wal=$_GET['atsold'];$typ=0;
		$detail.=Train($user,$wal,$typ);
	}
	if($_GET['defsold']){
		$wal=$_GET['defsold'];$typ=1;
		$detail.=Train($user,$wal,$typ);
	}
	if($_GET['spy']){
		$wal=$_GET['spy'];$typ=2;
		$detail.=Train($user,$wal,$typ);
	}
	if($_GET['reat']){
		$wal=$_GET['reat'];$typ=3;
		$detail.=Train($user,$wal,$typ);
	}
	if($_GET['redef']){
		$wal=$_GET['redef'];$typ=4;
		$detail.=Train($user,$wal,$typ);
	}

	//echo "--$typ--";
	die($detail);
	}



?>

Train Function Inside vsys.php it is too lengthy to post:

 

function Train($user,$wal,$type)
{
$nogold="Not enough plasma!";
$nosold="Not enough untrained colonists!";
if($type==0){
	$pris=2000*$wal;
	if($pris <= ($user->gold)){
		$q = @mysql_query("select untrainedSold from `UserDetails` where ID='$user->ID' ");
		$el=mysql_fetch_array($q, MYSQL_ASSOC);
		if($el[untrainedSold]>=$wal){
			$q = @mysql_query("update `UserDetails` set trainedAttackSold=trainedAttackSold+'$wal', untrainedSold=untrainedSold-'$wal', gold=gold-'$pris' where ID='$user->ID' ");
			if (!$q) {print ('Query failed: '.mysql_error());	return;	}
		}else return $nosold;
	}
	else return $nogold;
}
elseif($type==1){
	$pris=2000*$wal;
	if($pris <= ($user->gold)){
		$q = @mysql_query("select untrainedSold from `UserDetails` where ID='$user->ID' ");
		$el=mysql_fetch_array($q, MYSQL_ASSOC);
		if($el[untrainedSold]>=$wal){
			$q = @mysql_query("update `UserDetails` set trainedDefSold=trainedDefSold+'$wal', untrainedSold=untrainedSold-'$wal', gold=gold-'$pris' where ID='$user->ID' ");
			if (!$q) {print ('Query failed: '.mysql_error());	return;	}
		}else return $nosold;
	}
	else return $nogold;
}
elseif($type==2){
	$pris=3500*$wal;
	if($pris <= ($user->gold)){
		$q = @mysql_query("select untrainedSold from `UserDetails` where ID='$user->ID' ");
		$el=mysql_fetch_array($q, MYSQL_ASSOC);
		if($el[untrainedSold]>=$wal){
			$q = @mysql_query("update `UserDetails` set spies=spies+'$wal', untrainedSold=untrainedSold-'$wal', gold=gold-'$pris' where ID='$user->ID' ");
			if (!$q) {print ('Query failed: '.mysql_error());	return;	}
		}else return $nosold;

	}
	else return $nogold;
}
elseif($type==3){
	$q = @mysql_query("select trainedAttackSold from `UserDetails` where ID='$user->ID' ");
	$el=mysql_fetch_array($q, MYSQL_ASSOC);
	if($el[trainedAttackSold])$q = @mysql_query("update `UserDetails` set trainedAttackSold=trainedAttackSold-'$wal', untrainedSold=untrainedSold+'$wal' where ID='$user->ID' ");
}
elseif($type==4){
	$q = @mysql_query("select trainedDefSold from `UserDetails` where ID='$user->ID' ");
	$el=mysql_fetch_array($q, MYSQL_ASSOC);
	if($el[trainedDefSold])$q = @mysql_query("update `UserDetails` set trainedDefSold=trainedDefSold-'$wal', untrainedSold=untrainedSold+'$wal' where ID='$user->ID' ");
}
}

 

You should not need the getUserDetails function.

 

Ok the problem that I have here is that it simply does nothing, no error in error console, no training of troops, no php error, it just does nothing any help with this could be amazing!

 

Please Reply asap,

Brian Flores

 

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.