UPDATE won't; value is unchanged in MySQL table | Member | | Join Date: Aug 2007
Posts: 42
| |
ok here goes, this is killing me.
this is my attack script. - function attack(){
-
global $targetname;
-
$healthbefore = getValueID("health", "userdata", $_SESSION['id']);
-
$dmgrand= mt_rand(1,10);
-
$strength = 10;
-
$dmg = ($dmgrand * $strength);
-
$healthafter = ($healthbefore - $dmg);
-
if ($healthafter < 0){
-
$healthafter = 0;
-
}
-
updateValueUSER("health", "$healthafter", "userdata", "$targetname");
-
-
echo "Health before was $healthbefore. You dealt $dmg damage. $targetname now has $healthafter health left.";
-
}
here's updateValueUSER: - function updateValueUSER($column, $value, $table, $username){
-
global $conn;
-
$q = "UPDATE $table SET $column = $value WHERE username = '$username'";
-
$result = mysql_query($q,$conn);
-
}
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...
|  | Moderator | | Join Date: Jan 2007 Location: Colombo
Posts: 1,440
| | | 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.
|  | Moderator | | Join Date: Jan 2007 Location: Colombo
Posts: 1,440
| | | re: UPDATE won't; value is unchanged in MySQL table
Shall we print the Called Parameters First. - 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.$username;
-
}
|  | Site Moderator | | Join Date: Apr 2007 Location: Texas
Posts: 5,435
| | | re: UPDATE won't; value is unchanged in MySQL table
Alternatively (sorry Ajaxrand): -
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();
-
}
-
|  | Moderator | | Join Date: Jan 2007 Location: Colombo
Posts: 1,440
| | | re: UPDATE won't; value is unchanged in MySQL table Quote:
Originally Posted by pbmods Alternatively (sorry Ajaxrand): -
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();
-
}
-
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
| | | 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
| | | re: UPDATE won't; value is unchanged in MySQL table
Alright well it first gave me: -
"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: -
"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
| | | 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, - 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
| | | 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
|  | Site Moderator | | Join Date: Apr 2007 Location: Texas
Posts: 5,435
| | | 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
| | | 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!
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,471 network members.
|