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
https://forums.phpfreaks.com/topic/131568-php-mysql-addition-help/
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'

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.