Jump to content

PHP MySQL Addition Help


Stalingrad

Recommended Posts

Hello. I'm trying to program a simple game that you can earn credits from. The only problem is that when it runs the PHP code to give the winner their credits, it inserts the amount they won as their credits. I want it to add the new amount to their existing credits. Would somebody please tell me where I'm going wrong? Here's my code:

 

<?php
include("../config.php");
$jquery = mysql_query("SELECT * FROM drawjackpot WHERE id='1'");
while($jrow = mysql_fetch_array($jquery)) {
$jackpot = $jrow['jackpot'];
}
$count = mysql_num_rows(mysql_query("SELECT *  FROM dailydraw"));
$random = rand(1,$count);
$query = mysql_query("SELECT *  FROM dailydraw WHERE drawid='$random'");
while($row = mysql_fetch_array($query)) {
$winner = $row['username'];
}
mysql_query("UPDATE drawjackpot SET winner='$winner'");
mysql_query("UPDATE users SET credits='credits'+$jackpot WHERE username='$winner'"); // Here's the line for adding the credits.
mysql_query("INSERT INTO messages (userto, userfrom, subject, body, datesent, status) VALUES ('$winner', '', 'Congradulations!','Congradulations! You have won today's Daily Draw!', '$thedate', 'Unread'");

echo "$random $ubspace $winner $ubspace $count $ubspace $jackpot";
?>

 

Any help is greatly appreciated, and thank you in advance! =]

Link to comment
Share on other sites

Sorry, I realise you must be new but, I've got to say.... that is some of the worst code I've seen, but anyway....

 

Change this query....

 

UPDATE users SET credits='credits'+$jackpot WHERE username='$winner'

 

to....

 

UPDATE users SET credits=credits+$jackpot WHERE username='$winner'

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.