Jump to content

Recommended Posts

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']

 

Link to comment
https://forums.phpfreaks.com/topic/89070-solved-help-with-code/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/89070-solved-help-with-code/#findComment-456364
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/89070-solved-help-with-code/#findComment-456379
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.