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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.