Connecting Tech Pros Worldwide Forums | Help | Site Map

UPDATE won't; value is unchanged in MySQL table

Member
 
Join Date: Aug 2007
Posts: 42
#1: Aug 21 '07
ok here goes, this is killing me.

this is my attack script.

Expand|Select|Wrap|Line Numbers
  1. function attack(){
  2.     global $targetname;
  3.     $healthbefore = getValueID("health", "userdata", $_SESSION['id']);
  4.     $dmgrand= mt_rand(1,10);
  5.     $strength = 10;
  6.     $dmg = ($dmgrand * $strength);
  7.     $healthafter = ($healthbefore - $dmg);
  8.     if ($healthafter < 0){
  9.         $healthafter = 0;
  10.     }
  11.     updateValueUSER("health", "$healthafter", "userdata", "$targetname");
  12.  
  13.     echo "Health before was $healthbefore. You dealt $dmg damage. $targetname now has $healthafter health left.";
  14. }
here's updateValueUSER:

Expand|Select|Wrap|Line Numbers
  1. function updateValueUSER($column, $value, $table, $username){
  2.     global $conn;
  3.     $q = "UPDATE $table SET $column = $value WHERE username = '$username'";
  4.     $result = mysql_query($q,$conn);
  5. }
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...

ak1dnar's Avatar
Moderator
 
Join Date: Jan 2007
Location: Colombo
Posts: 1,440
#2: Aug 21 '07

re: UPDATE won't; value is unchanged in MySQL table


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.
ak1dnar's Avatar
Moderator
 
Join Date: Jan 2007
Location: Colombo
Posts: 1,440
#3: Aug 21 '07

re: UPDATE won't; value is unchanged in MySQL table


Shall we print the Called Parameters First.

Expand|Select|Wrap|Line Numbers
  1. function updateValueUSER($column, $value, $table, $username){
  2.     global $conn;
  3. //$q = "UPDATE $table SET $column = $value WHERE username = '$username'";
  4. //$result = mysql_query($q,$conn);
  5. echo $column. $value. $table.$username;
  6. }
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#4: Aug 21 '07

re: UPDATE won't; value is unchanged in MySQL table


Alternatively (sorry Ajaxrand):
Expand|Select|Wrap|Line Numbers
  1. function updateValueUSER($column, $value, $table, $username){
  2.     global $conn;
  3.     $q = "UPDATE $table SET $column = $value WHERE username = '$username'";
  4.     $result = mysql_query($q,$conn);
  5.  
  6.     echo $q, '<br /><br />', mysql_error();
  7. }
  8.  
ak1dnar's Avatar
Moderator
 
Join Date: Jan 2007
Location: Colombo
Posts: 1,440
#5: Aug 21 '07

re: UPDATE won't; value is unchanged in MySQL table


Quote:

Originally Posted by pbmods

Alternatively (sorry Ajaxrand):

Expand|Select|Wrap|Line Numbers
  1. function updateValueUSER($column, $value, $table, $username){
  2.     global $conn;
  3.     $q = "UPDATE $table SET $column = $value WHERE username = '$username'";
  4.     $result = mysql_query($q,$conn);
  5.  
  6.     echo $q, '<br /><br />', mysql_error();
  7. }
  8.  

Oh Yes that's cool, then you have the chance to find out what's going on with the Connection,Query String.
Member
 
Join Date: Aug 2007
Posts: 42
#6: Aug 21 '07

re: UPDATE won't; value is unchanged in MySQL table


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.
Member
 
Join Date: Aug 2007
Posts: 42
#7: Aug 21 '07

re: UPDATE won't; value is unchanged in MySQL table


Alright well it first gave me:
Expand|Select|Wrap|Line Numbers
  1. "UPDATE userdata SET health = 80 WHERE username = 'reallylongnamehi'"
and then it told me that username was invalid, which it was, so i set that to user.

now it gives me:
Expand|Select|Wrap|Line Numbers
  1. "UPDATE userdata SET health = 40 WHERE user = 'reallylongnamehi'"
without an error. Still doesn't update the entry even though it seems that everything should be working...
Member
 
Join Date: Aug 2007
Posts: 42
#8: Aug 21 '07

re: UPDATE won't; value is unchanged in MySQL table


Another thing i've noticed is that when I add another function I made to retrieve data,
Expand|Select|Wrap|Line Numbers
  1. echo getValueUSER("health", "userdata", "$targetname");
it gives me the correct value for health after the attack. that means it must be getting reset somewhere...
Member
 
Join Date: Aug 2007
Posts: 42
#9: Aug 21 '07

re: UPDATE won't; value is unchanged in MySQL table


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
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#10: Aug 21 '07

re: UPDATE won't; value is unchanged in MySQL table


Heya, akapsycho.

Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Member
 
Join Date: Aug 2007
Posts: 42
#11: Aug 21 '07

re: UPDATE won't; value is unchanged in MySQL table


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!
Reply