Help with PHP/MySQL code?

Discussion in 'PHP' started by mokimofiki, Aug 18, 2008.

  1. #1
    This code doesn't seem to work and I'm not sure why. I have been looking at the entire page that has been created and the only area that seems to not work is below.

    Obviously you can't see how my tables are setup although I was hoping that someone could notice something that may be obvious that I am overlooking.

    $previousenergy = mysql_query("SELECT energy FROM playerstats WHERE name = 'Moki'");
    
    $currentenergy = ("$previousenergy" + 5);
    
    mysql_query("UPDATE playerstats SET energy = '$currentenergy' WHERE name = 'Moki'");
    
    mysql_close($con);
    Code (markup):
    Thank you in advance,
    Brandon A.K.A Moki Mofiki
     
    mokimofiki, Aug 18, 2008 IP
  2. graham23s

    graham23s Well-Known Member

    Messages:
    188
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    105
    #2
    Hi Mate,

    What is the error you are getting: can you place

    error_reporting(0);

    at the top of your script!

    Graham
     
    graham23s, Aug 18, 2008 IP
  3. rohan_shenoy

    rohan_shenoy Active Member

    Messages:
    441
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #3
    
    UPDATE playerstats SET energy = energy+$change_in_energy WHERE name = 'Moki'
    #Where $change_in_energy is the increase/decrease AND 'energy' is an integer type of field!
    
    Code (SQL):
    JFYI,
    In your previous code, '$previousenergy' is a resource, not an integer or a string. You will need to use the mysql_result() function to get the from data of it!
     
    rohan_shenoy, Aug 18, 2008 IP
  4. mokimofiki

    mokimofiki Well-Known Member

    Messages:
    444
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #4
    Thank you it works great!!!!
     
    mokimofiki, Aug 18, 2008 IP