Jump to content

[resolved] Bank Not Working


kirbyweb

Recommended Posts

<?phpinclude('_______');//calculate money needed for next level of bank upgrade (php part of file)$need_money = 500;?><form>Bank level: <?php echo $username['bank'];?> <br>Next level: <input type="submit" value="<?php echo number_format($need_money);?> money" name="upgradebank"></form><?php//now we create another php part of this fileif ($_POST['upgradebank']) {//we check if user has enough money to upgrade bankif ($username['money'] != $need_money) {//we use die function to stop script execution and to show message what is wrongdie("You don't have enough money to upgrade Bank!");}//everything is OK, we update our user tablemysql_query("UPDATE `castle wars users` SET money=money-'$need_money', bank=bank+'1' WHERE id='$username[id]'") or die(mysql_error());}?>

This code is not working when I click the button it does not display the error like it is suppose to please help.

Link to comment
Share on other sites

  • Replies 55
  • Created
  • Last Reply

Like I want to make it so if the money is at 500 it stops all scripts so it stays at 500, but I have another file that has include ('____');And it stops all scripts in that file, how can I make it so it includes the file but it does not stop the scripts in the new file.

Link to comment
Share on other sites

The exit or die statements will immediately stop all execution. If you include a file, it will execute the code in the included file. If you are in an included file and you want to stop execution in the included file and return to the parent file then you can use a return statement. You can use a break statement to escape out of a control structure like a loop.

Link to comment
Share on other sites

<?phpinclude ('_____');//calculate money needed for next level of bank upgrade (php part of file)$need_money = 200;?><form method='POST'>Bank level: <?php echo $username['bank'];?> <br>Next level: <input type="submit" value="<?php echo number_format($need_money);?> money" name="upgradebank"></form><?php//now we create another php part of this fileif ($_POST['upgradebank']) {//we check if user has enough money to upgrade bankif ($username['money'] > $need_money) {//we use die function to stop script execution and to show message what is wrongdie("You don't have enough money to upgrade Bank!");}//everything is OK, we update our user tablemysql_query("UPDATE `castle wars users` SET money=money-'$need_money', bank=bank+'1' WHERE id='$username[id]'") or die(mysql_error());}?>

Link to comment
Share on other sites

<?phpsession_start();$user = $_SESSION['username'];//open my database$connect = mysql_connect('_________', '_______', '____') or die('Couldn\'t connect!');mysql_select_db('_________');$query = mysql_query("SELECT * FROM `castle wars users` WHERE username = '$user'");$username = mysql_fetch_array($query);$last = $username['lastupdate']; //timestamp from db$extraTime = time() - $last;$money = floor($extraTime / 60);if ($username['money']>=500&&$username['bank']<1){die('User\s money 500');}if ($money > 0) {	//lets update users table	mysql_query("UPDATE `castle wars users` SET lastupdate=lastupdate+$extraTime, money=money+$money WHERE id= '$username[id]'") or die(mysql_error());}echo 'user\'s money:'. ((int)$username['money']+(int)$money) .'money.';?>

Link to comment
Share on other sites

Why not just echo the text you want and have the rest of the include content in an if statement?If you want to return from an include file, you need to handle the return somehow, it's the same as with functions. If you have this include file:

<?php$var = 'some text';return $var;?>

And you include that file like this:

<?php$value = include 'file.php';echo $value;?>

Then you can use $value to store whatever the include file returned.

Link to comment
Share on other sites

It's probably easiest to just use if statements to make sure that the code only runs if the conditions are true. Your code right now exits if the conditions are true, so instead of exiting if things are true, you would only run the rest of the code if the conditions are not true.

Link to comment
Share on other sites

Yes. Use an if statement to only execute the code if the user has less than 500 and the bank is greater than 0. You can even use an else statement to show a message if either of those was not true. That's the easiest way to do it, I don't know how to explain it better than that.

Link to comment
Share on other sites

Archived

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


×
×
  • Create New...