BellQuestWars Posted April 22, 2011 Share Posted April 22, 2011 <?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... Quote Link to comment https://forums.phpfreaks.com/topic/234476-why-isnt-this-script-working/ Share on other sites More sharing options...
Maq Posted April 22, 2011 Share Posted April 22, 2011 Look at the MySQL UPDATE syntax: http://dev.mysql.com/doc/refman/5.0/en/update.html You're not specifying table names so your queries are failing. Quote Link to comment https://forums.phpfreaks.com/topic/234476-why-isnt-this-script-working/#findComment-1205057 Share on other sites More sharing options...
KevinM1 Posted April 22, 2011 Share Posted April 22, 2011 Also, where's $name coming from? Quote Link to comment https://forums.phpfreaks.com/topic/234476-why-isnt-this-script-working/#findComment-1205059 Share on other sites More sharing options...
BellQuestWars Posted April 22, 2011 Author Share Posted April 22, 2011 Thanks, you guys are awesome, I hadn't even gotten done loading the page after I posted when I got a reply (slow internet...) Quote Link to comment https://forums.phpfreaks.com/topic/234476-why-isnt-this-script-working/#findComment-1205060 Share on other sites More sharing options...
Maq Posted April 22, 2011 Share Posted April 22, 2011 Also, where's $name coming from? Here: $name = $_SESSION["username"]; Quote Link to comment https://forums.phpfreaks.com/topic/234476-why-isnt-this-script-working/#findComment-1205061 Share on other sites More sharing options...
KevinM1 Posted April 22, 2011 Share Posted April 22, 2011 Also, where's $name coming from? Here: $name = $_SESSION["username"]; Why yes, apparently it is.... Quote Link to comment https://forums.phpfreaks.com/topic/234476-why-isnt-this-script-working/#findComment-1205076 Share on other sites More sharing options...
Maq Posted April 22, 2011 Share Posted April 22, 2011 Also, where's $name coming from? Here: $name = $_SESSION["username"]; Why yes, apparently it is.... You're drinking earlier than usual Quote Link to comment https://forums.phpfreaks.com/topic/234476-why-isnt-this-script-working/#findComment-1205084 Share on other sites More sharing options...
Pikachu2000 Posted April 22, 2011 Share Posted April 22, 2011 *Pikachu2000 wishes he had a big bottle of Grand Marnier Quote Link to comment https://forums.phpfreaks.com/topic/234476-why-isnt-this-script-working/#findComment-1205088 Share on other sites More sharing options...
KevinM1 Posted April 22, 2011 Share Posted April 22, 2011 Also, where's $name coming from? Here: $name = $_SESSION["username"]; Why yes, apparently it is.... You're drinking earlier than usual Well, if you start from yesterday, then it would be way later than usual. Quote Link to comment https://forums.phpfreaks.com/topic/234476-why-isnt-this-script-working/#findComment-1205094 Share on other sites More sharing options...
BellQuestWars Posted April 23, 2011 Author Share Posted April 23, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/234476-why-isnt-this-script-working/#findComment-1205109 Share on other sites More sharing options...
BellQuestWars Posted April 23, 2011 Author Share Posted April 23, 2011 Nevermind, I got it to work... W3Schools had the wrong syntax ... 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.) Quote Link to comment https://forums.phpfreaks.com/topic/234476-why-isnt-this-script-working/#findComment-1205197 Share on other sites More sharing options...
Maq Posted April 25, 2011 Share Posted April 25, 2011 Yep w3schools is not a reliable resource, check out Nightslyr's sig link. Quote Link to comment https://forums.phpfreaks.com/topic/234476-why-isnt-this-script-working/#findComment-1205774 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.