473,382 Members | 1,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Javascript not working

The1corrupted
134 100+
I don't know if this is the right forum or not, but right now, my Javascript, that is embedded in PHP, is not working! It works everywhere else but not here. HELP!!

[PHP]
<?php
$soldnumber=$_POST['soldier'];
$cavnumber=$_POST['cavalry'];
$artnumber=$_POST['artillary'];

if ($marray['havetank']==1) {
$tanknumber=$_POST['tank'];
$tanktotal=$tanknumber*$tankcost;
}
if ($marray['haveair']==1) {
$fnumber=$_POST['fighter'];
$bnumber=$_POST['bomber'];
$btotal=$fnumber*$fcost;
$btotal=$bnumber*$bcost;
}

$currmoney=$genarray['money'];

$soldtotal=($soldcost*$soldnumber);
$cavtotal=($cavcost*$cavnumber);
$arttotal=($artcost*$artnumber);

if ($soldnumber!=NULL OR $cavnumber!=NULL OR $artnumber!=NULL) {
if ($soldnumber!=NULL AND $soldnumber>0) {
if ($soldtotal<$currmoney) {
$currmoney=($currmoney-$soldtotal);
$totals2=$totals2.$soldnumber." soldiers.\n";
mysql_query("UPDATE `military` SET `soldiers`=`soldiers`+'$soldnumber' WHERE `id`='$id'");
mysql_query("UPDATE `users` SET `money`=`money`-'$soldtotal' WHERE `id`='$id'");
} else {
echo "<script language=\"javascript\" type=\"text/javascript\">alert(\"Not enough for soldiers!\")</script>";
}
}

if ($cavnumber!=NULL AND $cavnumber>0) {
if ($cavtotal<$currmoney) {
$currmoney=($currmoney-$cavtotal);
$totals2=$totals2.$cavnumber." cavalry.\n";
mysql_query("UPDATE `military` SET `cavalry`=`cavalry`+'$cavnumber' WHERE `id`='$id'");
mysql_query("UPDATE `users` SET `money`=`money`-'$cavtotal' WHERE `id`='$id'");
} else {
echo "<script language=\"javascript\" type=\"text/javascript\">alert(\"Not enough for cavalry!\")</script>";
}
}

if ($artnumber!=NULL AND $artnumber>0) {
if ($arttotal<$currmoney) {
$currmoney=($currmoney-$arttotal);
$totals2=$totals2.$artnumber." artillary.\n";
mysql_query("UPDATE `military` SET `artillary`=`artillary`+'$artnumber' WHERE `id`='$id'");
mysql_query("UPDATE `users` SET `money`=`money`-'$arttotal' WHERE `id`='$id'");
} else {
echo "<script language=\"javascript\" type=\"text/javascript\">alert(\"Not enough for artillary!\")</script>";
}
}

if ($tanknumber!=NULL AND $tanknumber>0 AND $genarray['havetank']==1) {
if ($tanktotal<$currmoney) {
$currmoney=($currmoney-$tanktotal);
$totals2=$totals2.$tanknumber." tanks.\n";
mysql_query("UPDATE `military` SET `tanks`=`tanks`+'$tanknumber' WHERE `id`='$id'");
mysql_query("UPDATE `users` SET `money`=`money`-'$tanktotal' WHERE `id`='$id'");
} else {
echo "<script language=\"javascript\" type=\"text/javascript\">alert(\"Not enough for tanks!\")</script>";
}
}

if ($fnumber!=NULL AND $fnumber>0 AND $genarray['haveair']==1) {
if ($ftotal<$currmoney) {
$currmoney=($currmoney-$ftotal);
$totals2=$totals2.$fnumber." fighters.\n";
mysql_query("UPDATE `military` SET `fighters`=`fighters`+'$fnumber' WHERE `id`='$id'");
mysql_query("UPDATE `users` SET `money`=`money`-'$ftotal' WHERE `id`='$id'");
} else {
echo "<script language=\"javascript\" type=\"text/javascript\">alert(\"Not enough for fighters!\")</script>";
}
}

if ($bnumber!=NULL AND $bnumber>0 AND $genarray['haveair']==1) {
if ($btotal<$currmoney) {
$currmoney=($currmoney-$btotal);
$totals2=$totals2.$bnumber." bombers.\n";
mysql_query("UPDATE `military` SET `bombers`=`bombers`+'$bnumber' WHERE `id`='$id'");
mysql_query("UPDATE `users` SET `money`=`money`-'$btotal' WHERE `id`='$id'");
} else {
echo "<script language=\"javascript\" type=\"text/javascript\">alert(\"Not enough for bombers!\")</script>";
}

echo "<script language=\"javascript\" type=\"text/javascript\">alert(\"You Purchased:\n\" + \"".$totals2."\");
parent.location=\"viewempire.php?id=\"".$_SESSION['user']."\"
</script>";
}
}
?>
[/PHP]
Nov 22 '07 #1
6 2438
Atli
5,058 Expert 4TB
Hi.

How is it not working as you expect it to?

Could you show us the source from your browser, to see what exactly it is that your browser is getting.
Nov 23 '07 #2
The1corrupted
134 100+
Actually, I've decided to trash that method. Instead, I have a new issue. I want there to be a confirmation message with javascript and if the user hits "Ok", then all the mysql_queries go through. Else, he's simply redirected so I'm just wondering how I can transfer variables from javascript to php.. And how I should go about structuring that...
Nov 24 '07 #3
Markus
6,050 Expert 4TB
Actually, I've decided to trash that method. Instead, I have a new issue. I want there to be a confirmation message with javascript and if the user hits "Ok", then all the mysql_queries go through. Else, he's simply redirected so I'm just wondering how I can transfer variables from javascript to php.. And how I should go about structuring that...
Cookies maybe? A rough thing to do, but i know nothing!
Nov 24 '07 #4
... so I'm just wondering how I can transfer variables from javascript to php.. And how I should go about structuring that...
One method, and the one that I'm using, is to use a XhttpRequest, and posting/sending (POST/GET) your variables to php.
Nov 24 '07 #5
The1corrupted
134 100+
How does that all work?
Nov 24 '07 #6
It goes by the name of AJAX, basic stuff:
http://www.w3schools.com/php/php_ajax_intro.asp

Also, if you do not need to send the variable immediately to php, rather you could wait until the nex page load, there are such alternatives, as a quick google search revealed; google javascript variable to php.

(btw, this is now officially a javascript question...)
Nov 24 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: VictorG | last post by:
Hello, I am new to JS and am trying to add some HTML into a JS function. So that when called the script as well as the HTML will be invoked. Is there some type of embed mechanism, sort of the...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
1
by: Muhammad Abdullah | last post by:
Hi am having some problems with the javascript confirm. i have it working fine on one page and it doesnt even pop up at the other. The code on the working page is, private void...
1
by: den2005 | last post by:
Hi everybody, I am confused and still looking why this codes is not working. Can anyone notice or know why this code is not working? Thanks in advance. Code working: <form id="form1"...
11
by: Nathan Sokalski | last post by:
I add several JavaScript events (onchange, onkeypress, etc.) to Controls using the Add method of the Attributes collection. However, if the JavaScript code contains certain characters, such as & or...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.