Jump to content
xisto Community

Cant Find The Error

Recommended Posts

In this code I want to retrieve the energy and max energy of a players account, then add 8% to energy of maxenergy, hen if energy is bigger than maxenergy, energy is then made equal to maxenergy. Then the database is updated.I don't understand why it's not working.

$query=mysql_query("SELECT MAX(id) as maxid FROM `accounts` LIMIT 1");$row = mysql_fetch_assoc($query);$id = $row['maxid'];  $query = "SELECT * FROM `accounts`"; $result=mysql_query($query);while ($row=mysql_fetch_assoc($result)) {$energy = $row['energy'];$maxenergy = $row['maxenergy'];}for($i=1; $i<="$id"; $i++) {$query = "SELECT * FROM `accounts` WHERE (id) = '".$id."'";$result=mysql_query($query);$addenergy = (0.08 * $maxenergy);$energy = ($addenergy + $energy);if($energy > $maxenergy) {$energy = $maxenergy;}$query = "UPDATE `account` SET (energy) = '".$energy."' WHERE (id) = '".$id."'";$result = mysql_query($query);echo" The energy script worked!";}

Share this post

Link to post
Share on other sites

maybe if you tell us what error messages you get. it would be easier for us to help you :mellow:?


EDIT: I THINK that you can't make the energy get higher, or? well, if thats your problem, you should try to add this:


$energy = ($addenergy += $energy);

If thats the fault, then that should be the solution. And remember to write what your problem is, and NOT ONLY what you want to accomplish. because we can hardly guess what your problem is.


And another thing :D the "the energy script worked" echo, wont work as you think. it will execute whatever happens, becuse you have no if statement :o

Edited by Feelay (see edit history)

Share this post

Link to post
Share on other sites

A very usefull trick to debug sql query is to add 'or die(mysql_error())' after every query you make, this way your script will stop once SQL throws an error and the error will be shown to you.


$result = mysql_query($query) or die(mysql_error());

Another usefull trick is to echo variables so you can actualy see their values instead of guessing and hoping.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.