script not redirecting when query fails
I have the following lines of code
if(isset($_GET['course_id'])) {
$data_id = mysql_real_escape_string($_GET['course_id']);
$subscriptionVerification = "SELECT `user_id`, `course_id` FROM
subscriptions WHERE `user_id` = '".$user_id."' and
`course_id`='".$data_id."'";
$subscriptionResult = mysql_query($subscriptionVerification);
if(!mysql_num_rows($subscriptionResult)===1)
{
header("location:login.php");
die(); // sends user to the login page if their userID and
subscription code do not match the page they are trying to
retrieve
}
}
the problem is that when i get the course_id from
chapters.php?course_id=1234 and if that id doesnt exist in the mysql db,
it still loads the page instead of redirecting.
if I write if(mysql_num_rows($subscriptionResult)===1) without the ! then
it does work and it directs all traffic (including the correct course ids)
over.
I'm wondering if there's something I'm doing wrong. I've tried the
following two variations as well if(!$subscriptionResult) and
if($subscriptionResult===FALSE) but neither have worked.
the purpose of this is to avoid having people try to manually put in
course_id (especially ones that don't exist) and load the page with
content in it.
No comments:
Post a Comment