Jump to content

Set to -1000


bongo13

Recommended Posts

well, heres my script

<?
$query = "select * from users where user_username = '$username'";
$result = mysql_query($query);

while ($row = mysql_fetch_array($result)) {
$old_points = $row['user_points'];
}

$points = $old_points - 1000;

$query = "UPDATE users SET user_points = '$points' WHERE user_username = '$user_name'";
$result = mysql_query($query);
?>

1.it sets the users points to -1000 when i want it to take away - 1000 from the original points
2. the variable $query is set before in the script, i tried putting $query1 in but it didnt make a difference

if you need any more information just post it and i'll see what i can do while you see what you can do.
Link to comment
https://forums.phpfreaks.com/topic/6919-set-to-1000/
Share on other sites

May I recomend the below method instead;

[code]
$query = "select user_points from users where user_username = '$username'";
$result = mysql_query($query);
list($old_points) = mysql_fetch_row($result);

$points = $old_points - 1000;

$query = "UPDATE users SET user_points = '$points' WHERE user_username = '$user_name'";
$result = mysql_query($query);
[/code]

Replacing the needless while loop with list($old_points) = mysql_fetch_row($result) saves some lines. And specifying in the query to only select the column you're working with will save time on the query as well.

A possible cause of your error I see is that in the first query you use $username, but in the update you use $user_name. Not sure which one holds the actual username you're using though, but you will want to double check that.
Link to comment
https://forums.phpfreaks.com/topic/6919-set-to-1000/#findComment-25134
Share on other sites

to avoid the whole issue, reference the original value itself:

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']UPDATE[/span] users SET user_points [color=orange]=[/color] user_points [color=orange]-[/color] 1000 [color=green]WHERE[/color] blah blah blah [!--sql2--][/div][!--sql3--]

you don't have to waste resources by grabbing it in the first place. mysql already knows the original value.
Link to comment
https://forums.phpfreaks.com/topic/6919-set-to-1000/#findComment-25160
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

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.