0

Am trying to redirect a user to a page if some condition are true but it keep redirecting to the first page whether or not the condition is true. Here is my code:

if($level ="100_level")
{
    header("location:course_reg.php");                      
}else {
    header("location:course_reg_200_level.php");            
}

3 Answers 3

4

In the condition the value was being assigned to $level instead of condition checking. In any cases, the conditions is true.

To fix, Put double equal (==) to your if condition,

if($level == "100_level")
Sign up to request clarification or add additional context in comments.

Comments

1

when this happen, that means you have problem with your condition or your code. First of all, please change the equal sign to below.

if($level == "100_level")

Comments

0

If you have 1 = sign, you make level exactly equal to the right side of the sign.

If you check for ==, then you are making sure that it is in fact exactly "100_level"

Don't forget to put exit(); after your header redirect code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.