1

While running my code on localhost I had a problem with the include command.

Here's my code:

<?php
 $res = 2; // this also can be change to any number. it is based on user input, but for simply the problem i make it to be set manually
 If ($res =1,){

    $open = include ("weekend.php");
}
else{
    $open = include ("weekday.php");
}
echo $open;
?>

I expected the output to be weekday.php, but the output is weekend.php. It works fine if I use $res = 1.

1
  • 2
    correct your if condition......... If ($res =1) changes into if ($res == 1) Commented Jan 1, 2019 at 6:34

1 Answer 1

2

Besides the obvious typos (the capital I in If, the comma at the end of the condition), you're using the wrong operator. = is the assignment operator. In order to check equality, you should use the == operator:

if ($res == 1) {
    // ---^
    $open = include ("weekend.php");
}
else {
    $open = include ("weekday.php");
}
Sign up to request clarification or add additional context in comments.

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.