Stalingrad Posted November 6, 2008 Share Posted November 6, 2008 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 More sharing options...
trq Posted November 6, 2008 Share Posted November 6, 2008 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 https://forums.phpfreaks.com/topic/131568-php-mysql-addition-help/#findComment-683359 Share on other sites More sharing options...
Stalingrad Posted November 6, 2008 Author Share Posted November 6, 2008 Thanks a bunch! =] Link to comment https://forums.phpfreaks.com/topic/131568-php-mysql-addition-help/#findComment-683360 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.