1.)I have a mysql table -app_challenges- with the columns: level, id, difficulty, link, password, points. I also have a table -mission_scores- with the fields: user_id, challenge_id and score.
2.)When someone submits a password, it goes to levelup.php?id=# (# being the number in the `id` column from `app_challenges`)
3.)A mysql query is performed to check if the posted password matches the password in `app_challenges`
4.)If the password is wrong, it will echo that it is wrong. If it's correct, a query will be performed to check the `challenge_id` and `user_id` column in the mission_scores table for a match. (user_id is the person's username)
5.)If the second query returns that the person has yet to complete the level (returns 0 rows) it will insert the information into `mission_scores` but if there IS a row that shows that that level has been beaten, it will say "points have already been added to your score"
My password check query works fine but my second query isn't functioning correctly because it always returns that there is 0 matches in the `mission_scores` table, even if someone has beaten that level already.
Here is my second query:
Code: Select all
<?php
if($_POST['password'] != "".$row['password']."")
{
echo "Incorrect Password";
}
else
{
$query = "SELECT * FROM `mission_scores` a RIGHT JOIN `app_challenges` b ON a.`user_id` = '{$_SESSION['user']}' AND a.`challenge_id` = b.`Level` WHERE b.`id` = '{$_GET['id']}'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_assoc($result);
}
if($row['challenge_id'] == 1)
{
echo "Points have already added to your score";
}
else
{
echo "<center><h2>Good job! You beat ".$row['Level']."!</h2><h4>".$row['points']." points have been added to your score!</h4>";
$user = $_SESSION["user"];
$mission = "".$row['Level']."";
$points = "".$row['points']."";
$query = "INSERT INTO mission_scores VALUES('$user','$mission','$points')";
$result = mysql_query($query) or die(mysql_error());
}
?>