UPDATE won't; value is unchanged in MySQL table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • akapsycho
    New Member
    • Aug 2007
    • 43

    UPDATE won't; value is unchanged in MySQL table

    ok here goes, this is killing me.

    this is my attack script.

    [CODE=php]function attack(){
    global $targetname;
    $healthbefore = getValueID("hea lth", "userdata", $_SESSION['id']);
    $dmgrand= mt_rand(1,10);
    $strength = 10;
    $dmg = ($dmgrand * $strength);
    $healthafter = ($healthbefore - $dmg);
    if ($healthafter < 0){
    $healthafter = 0;
    }
    updateValueUSER ("health", "$healthaft er", "userdata", "$targetnam e");

    echo "Health before was $healthbefore. You dealt $dmg damage. $targetname now has $healthafter health left.";
    }[/CODE]

    here's updateValueUSER :

    [CODE=php]function updateValueUSER ($column, $value, $table, $username){
    global $conn;
    $q = "UPDATE $table SET $column = $value WHERE username = '$username'";
    $result = mysql_query($q, $conn);
    }[/CODE]

    the problem is that it never sets the value of "health" in the database to $healthafter. every time I try to check the health, it's back at 100. anyone have an idea? this is really killing me...
    Last edited by ak1dnar; Aug 21 '07, 01:00 PM. Reason: Added the Language For the [Code=xxx] Tags
  • ak1dnar
    Recognized Expert Top Contributor
    • Jan 2007
    • 1584

    #2
    akapsycho,

    A Thread Title Like; about to pull my hair out, mysql & php question
    Not Strong enough to describe your question.

    You may better to Go through FAQ
    Thanks for your time.

    Comment

    • ak1dnar
      Recognized Expert Top Contributor
      • Jan 2007
      • 1584

      #3
      Shall we print the Called Parameters First.

      [CODE=php]function updateValueUSER ($column, $value, $table, $username){
      global $conn;
      //$q = "UPDATE $table SET $column = $value WHERE username = '$username'";
      //$result = mysql_query($q, $conn);
      echo $column. $value. $table.$usernam e;
      }[/CODE]

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Alternatively (sorry Ajaxrand):
        [code=php]
        function updateValueUSER ($column, $value, $table, $username){
        global $conn;
        $q = "UPDATE $table SET $column = $value WHERE username = '$username'";
        $result = mysql_query($q, $conn);

        echo $q, '<br /><br />', mysql_error();
        }
        [/code]

        Comment

        • ak1dnar
          Recognized Expert Top Contributor
          • Jan 2007
          • 1584

          #5
          Originally posted by pbmods
          Alternatively (sorry Ajaxrand):
          [code=php]
          function updateValueUSER ($column, $value, $table, $username){
          global $conn;
          $q = "UPDATE $table SET $column = $value WHERE username = '$username'";
          $result = mysql_query($q, $conn);

          echo $q, '<br /><br />', mysql_error();
          }
          [/code]
          Oh Yes that's cool, then you have the chance to find out what's going on with the Connection,Quer y String.

          Comment

          • akapsycho
            New Member
            • Aug 2007
            • 43

            #6
            Sorry about the title, I was going crazy and I put it up there in desperation. I've already tried echoing all the parameters and they are all exactly what they should be. I'll try

            echo $q, '<br /><br />', mysql_error();

            and see what that does. What is it supposed to do? Thanks for your help.

            Comment

            • akapsycho
              New Member
              • Aug 2007
              • 43

              #7
              Alright well it first gave me:
              [code=mysql]
              "UPDATE userdata SET health = 80 WHERE username = 'reallylongname hi'"[/code]

              and then it told me that username was invalid, which it was, so i set that to user.

              now it gives me:
              [code=mysql]
              "UPDATE userdata SET health = 40 WHERE user = 'reallylongname hi'"[/code]

              without an error. Still doesn't update the entry even though it seems that everything should be working...

              Comment

              • akapsycho
                New Member
                • Aug 2007
                • 43

                #8
                Another thing i've noticed is that when I add another function I made to retrieve data,
                [code=php]echo getValueUSER("h ealth", "userdata", "$targetnam e");[/code] it gives me the correct value for health after the attack. that means it must be getting reset somewhere...

                Comment

                • akapsycho
                  New Member
                  • Aug 2007
                  • 43

                  #9
                  ARGH got it...I was using $_SESSION['id'] instead of the target's id...man I feel dumb right now...thanks for all of your help

                  Comment

                  • pbmods
                    Recognized Expert Expert
                    • Apr 2007
                    • 5821

                    #10
                    Heya, akapsycho.

                    Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)

                    Comment

                    • akapsycho
                      New Member
                      • Aug 2007
                      • 43

                      #11
                      Thanks a lot pbmods. I've been pleasantly surprised by how constructive this forum is and I'll be sure to look around if I can find anyone who I can help. Thanks for everyone's help again!

                      Comment

                      Working...