Jump to content

Why isnt this script working?


BellQuestWars

Recommended Posts

<?php
session_start();
require_once("connect.php");
?>
<html>
<body>
Thanks for buying!<br> Receipt:<br> Amount:<?php echo ($_POST["amount"]);?>
<br>Type:<?php echo $_POST["type"];?>
<br>Cost:<?php
if($_POST["type"]=="pikemen"){
$cost = 20 * $_POST["amount"];
$price = $_SESSION["resources"] - $cost;
$name = $_SESSION["username"];
$gained = $_POST["amount"] + $_SESSION["pikemen"];
mysql_query("UPDATE SET pikemen = '$gained'
WHERE username = '$name'");
}
mysql_query("UPDATE SET resources = '$price'
WHERE username = '$name'");
?>
</body>
</html>

 

The script is supposed to use some information taken from an input box on the previous page to buy items from the shop, but its not working (it doesnt give errors, just doesnt change the amount of soldiers or resources...

Link to comment
https://forums.phpfreaks.com/topic/234476-why-isnt-this-script-working/
Share on other sites

:( it still isnt even working, and I changed it to this:

<?php
session_start();
require_once("connect.php");
?>
<html>
<body>
Thanks for buying!<br> Receipt:<br> Amount:<?php echo ($_POST["amount"]);?>
<br>Type:<?php echo $_POST["type"];?>
<br>Cost:<?php
if($_POST["type"]=="pikemen"){
// MySQL connect information.
$c_username = "a1369434_bqw";
$c_password = "darthvader1";
$c_host = "mysql7.000webhost.com";
$c_database = "a1369434_bqw";

// Connect.
$connection = mysql_connect($c_host, $c_username, $c_password)
or die ("It seems this site's database isn't responding.");
$cost = 20 * $_POST["amount"];
$price = $_SESSION["resources"] - $cost;
$name = $_SESSION["username"];
$gained = $_POST["amount"] + $_SESSION["pikemen"];
mysql_query("UPDATE SET pikemen = '$gained'
WHERE username = '$name'");
echo $cost;
}mysql_query("UPDATE SET resources = '$price'
WHERE username = '$name'");
?>
</body>
</html>

Nevermind, I got it to work... W3Schools had the wrong syntax :o...  Nightslyr's signature speaks the truth!

 

Please lock this topic, or whatever you do to solved topics (sorry bout all the double posting, I hadnt seen the modify button before now.)

Archived

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

×
×
  • 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.