Potatis Posted February 2, 2008 Share Posted February 2, 2008 I am trying to find out whether a person chose a particular answer for a specific game, and if so they win a bonus point. There are 8 games, and an admin chooses one of them to be match of the round, and that's the one that earns the bonus point. I want the bonus point to show in a column in my users table, the column is "motr" (match of the round) and is added to the total points which is also in the "users" table. I have tried a lot of different codes, nothing works fully. The latest one tests every single answer in the "games" table, where game1, game2, game3 etc has an answer from the user stored. It doesn't work. When the admin scores the quiz, the correct number of right and wrong answers show, and one point is allocated to the total points for each correct answer, but the bonus point doesn't work. It gives a bonus point for every game, but I thought it would have answered false in the IF statement. Here is my appalling code from the last attempt. <?php // MOTR $motrnd = "1"; //value of bonus point $result = mysql_query("SELECT username FROM games WHERE round='$round' "); while($row = mysql_fetch_array($result)) { $name9=$row['username']; //attempt to get each answer to compare with admin's match of the round $g1=$row['game1']; $g2=$row['game2']; $g3=$row['game3']; $g4=$row['game4']; $g5=$row['game5']; $g6=$row['game6']; $g7=$row['game7']; $g8=$row['game8']; //Testing if the admin's submission of motr is true using IF if($g1 == $_POST['motr']){ //Add points if true mysql_query("UPDATE users SET motr = (motr + '1'), points = (points + '1') WHERE username = '$name9' ;") or die(mysql_error()); } //And again... if($g2 == $_POST['motr']){ mysql_query("UPDATE users SET motr = (motr + '1'), points = (points + '1') WHERE username = '$name9' ;") or die(mysql_error()); } if($g3 == $_POST['motr']){ mysql_query("UPDATE users SET motr = (motr + '1'), points = (points + '1') WHERE username = '$name9' ;") or die(mysql_error()); } if($g4 == $_POST['motr']){ mysql_query("UPDATE users SET motr = (motr + '1'), points = (points + '1') WHERE username = '$name9' ;") or die(mysql_error()); } if($g5 == $_POST['motr']){ mysql_query("UPDATE users SET motr = (motr + '1'), points = (points + '1') WHERE username = '$name9' ;") or die(mysql_error()); } if($g6 == $_POST['motr']){ mysql_query("UPDATE users SET motr = (motr + '1'), points = (points + '1') WHERE username = '$name9' ;") or die(mysql_error()); } if($g7 == $_POST['motr']){ mysql_query("UPDATE users SET motr = (motr + '1'), points = (points + '1') WHERE username = '$name9' ;") or die(mysql_error()); } if($g8 == $_POST['motr']){ mysql_query("UPDATE users SET motr = (motr + '1'), points = (points + '1') WHERE username = '$name9' ;") or die(mysql_error()); } } ?> Please, how can I get this disastrous code right??? It is giving a bonus point for every game even when the answer does not equal the value of $_POST['motr'] Quote Link to comment https://forums.phpfreaks.com/topic/89070-solved-help-with-code/ Share on other sites More sharing options...
Potatis Posted February 2, 2008 Author Share Posted February 2, 2008 Bump. :-\ Quote Link to comment https://forums.phpfreaks.com/topic/89070-solved-help-with-code/#findComment-456361 Share on other sites More sharing options...
PHP Monkeh Posted February 2, 2008 Share Posted February 2, 2008 Try changing your query to: $result = mysql_query("SELECT * FROM games WHERE round='$round' "); Chances are your $g1, $g2 etc are just getting a null or 0 value because you haven't actually queried the fields game1, game2 etc. Just as a test try echo-ing $g1 and $_POST['motr'] to see what their values are. Quote Link to comment https://forums.phpfreaks.com/topic/89070-solved-help-with-code/#findComment-456364 Share on other sites More sharing options...
Potatis Posted February 2, 2008 Author Share Posted February 2, 2008 Thanks very much, it was silly of me not to SELECT * . Now it echos the game answer just fine, so that part of the script is not working. I still haven't got the other bit right where 1 point is added to my users table, in the motr column. It comes up zero even if I pick the match of the round. My IF statement is wrong. Quote Link to comment https://forums.phpfreaks.com/topic/89070-solved-help-with-code/#findComment-456379 Share on other sites More sharing options...
Potatis Posted February 2, 2008 Author Share Posted February 2, 2008 No it works, thanks very much PHP Monkeh, I appreciate your help very much! Quote Link to comment https://forums.phpfreaks.com/topic/89070-solved-help-with-code/#findComment-456388 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.