I am trying to make a word game where people guess a phrase. The database (setphrase) has 5 columns (word1, word2, word3, word4 and word5) that the phrase is stored in. This functions properly but if we set the phrase as 4 words, it no longer works. any help?
get url :
/actions.php?action=phrase&name=$(queryencode ${user})&word1=$(queryencode $(1))&word2=$(queryencode $(2))&word3=$(queryencode $(3))&word4=$(queryencode $(4))&word5=$(queryencode $(5))
Function from actions.php
$sql="SELECT * FROM setphrase";
$correctanswer=mysql_query($sql);
while ($row = mysql_fetch_assoc($correctanswer)) {
if($word1 == $row['word1'] && $word2 == $row['word2'] && $word3 == $row['word3'] && $word4 == $row['word4'] && $word5 == $row['word5']) {
//check if ticket name exists
$sql = "SELECT (name) FROM entrants WHERE name = '$name'";
$result = mysql_query($sql) or trigger_error(mysql_error(), E_USER_ERROR);
$row = mysql_fetch_row($result);
if ($row[0] > 0) {
//Exists - update tickets
$sql="UPDATE entrants SET tickets=tickets+1 WHERE name='$name'";
$result=mysql_query($sql);
} else {
//Doesn't exist - create ticket
$sql="INSERT INTO entrants (name, tickets) VALUES ('$name', 1)";
$result=mysql_query($sql);
}
//check if phrase name exists
$sql = "SELECT (name) FROM phrase WHERE name = '$name'";
$result = mysql_query($sql) or trigger_error(mysql_error(), E_USER_ERROR);
$row = mysql_fetch_row($result);
if ($row[0] > 0) {
//Exists - update wins
$sql="UPDATE phrase SET wins=wins+1 WHERE name='$name'";
$result=mysql_query($sql);
echo "Congratulations $name! You have guessed the phrase and received an extra ticket. A win has also been added to your total wins on the leaderboard.";
//Delete the table rows
$sql="DELETE FROM setphrase";
$result=mysql_query($sql);
} else {
//Doesn't exist - create win
$sql="INSERT INTO phrase (name, wins) VALUES ('$name', 1)";
$result=mysql_query($sql);
echo "Congratulations $name! You have guessed the phrase and received an extra ticket. A win has also been added to your total wins on the leaderboard.";
//Delete the table rows
$sql="DELETE FROM setphrase";
$result=mysql_query($sql);
}
} else {
echo "Good guess, but that is not the right answer.";
}
}