I posted a problem with a select query for a mySQL database here yesterday. Thank you for all of your responses but none of them work and I cannot find the answer to what seems to be a simple problem. There are three possible scenarios. The database could have a 1, 0, or it will be empty for that column and username. I want to check the database to see if there is a 1 or 0 in it. If there is I want to redirect to a new page or otherwise move on. The code is for a test and if the student has already answered the question I want to forward them to a different page so they cannot update the form again. It seems like a simple select query and then if statement. So far I have tried these code bits.
mysql_query("SELECT questionone FROM test WHERE id = $session[id]");
if ( $questionone == '0' || $questionone == '1' )
{
header("Location: http://www.newpage.net/moduleone/answererror.php?".SID );
}
This code bit will forward to the newpage but the problem is if you try to go to a question where the database is empty it still forwards to the newpage. Somehow the database query is not recognizing the database is empty and skipping this block.
mysql_query("SELECT questionone FROM test WHERE id = $session[id]");
if ( questionone == '0' || questionone == '1' )
{
header("Location: http://www.newpage.net/moduleone/answererror.php?".SID );
}
If you take away the $ in front of the questionone in the if statement then the code is simply ignored and is skipped no matter what is in the database 1,0 or empty. Not what I need.
Finally I tried this.
$query = mysql_query("SELECT questionone FROM test WHERE id = $session[id]");
$answer = mysql_fetch_row($query);
if (!$answer[0] || ( $answer[0] == '1' || '0' ))
{
header("Location:http://www.newpage.net/moduleone/answererror.php?".SID );
}
Same thing here. This code does not recognize the database is empty and continues to execute to the new Location header. I don't understand why these code bits do not do what they are told. If there is a 1 or 0 in the database then go to the new location or otherwise skip. They do not have this action. Maybe I could check to see if the database is empty first and then redirect according to those results? I'm beginning to think this sort of thing is not possible but it has to be. It is so simple in concept but neither I or anyone else is able to solve this problem so far.
Should I try to go about this in a different way?
Thanks again for your reply's