Jump to content

elseif syntax


bwielk
Go to solution Solved by Jacques1,

Recommended Posts

Hello guys! I have literally started learning how to code. And I have come to the point when I got to deal with elseif syntax which is not working properly and messes up everything I have done so far. Here's the script

 

 

$password = "tulip";

 

 

if ($password == "tulip")
{
echo '<b>Hello!</b><br> Welcome to the website Blaise!';
} else {
echo '<b> The password or login is incorrect <br> Please try again </b>';
} elseif ( $password == "daisy") 
{
echo '<b> Welcome Kate! </b>;
}
 
 
When I type in "daisy" nothing goes on and everything just gets stuck. 
 
Any help or explanation? Thanks
Link to comment
Share on other sites

  • Solution

You can't have an "elseif" after an "else". The "else" marks the end of the statement (as in: If none of the above is true, execute the following code).

 

It's

if (...)
{
    ...
}
elseif (...)
{
    ...
}
elseif (...)
{
    ...
}

...

else
{
    ...
}

If your code "just gets stuck", that means you need to fix your error reporting as well. PHP always tells you exactly what's wrong.

Link to comment
Share on other sites

For the beginning, I'd rather watch some videos about how to code and after that, when I have understood more about basics and what's syntax and what's variable, to proceed to some books as I am more of a visual rather than a reader. Thanks a lot for Your advice, though. If You have more suggestions or recommendations, I am open towards everything :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.