0

I have a user registration and login form which has various error/success messages. I am trying to put my error box html code around each error message but am having a bit of difficulty.

The html for the error box is:

<div class="alert alert-info alert-login"> *error message here* <div>

My PHP looks like this:

$msg = 'login failed';

I have tried the following:

$msg = '<div class=\"alert alert-info alert-login\">login failed<br></div>';

However this did not work, is anyone able to shed some light as to why and how I am able to fix this? The message is showing but the div styling does not. Cheers!

0

3 Answers 3

3

Since you're using single quotes to encapsulate the string, you don't need to escape the double ones, so use:

$msg = '<div class="alert alert-info alert-login">login failed<br></div>';

More about strings and single quotes: http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.single

Sign up to request clarification or add additional context in comments.

1 Comment

I endeavour to please! Please click the checkmark to mark this answer as accepted if you liked it.
1

You don't need to use slashes if the apostrophes are different.

$msg = '<div class="alert alert-info alert-login">login failed<br></div>';
       ^           ^

Comments

0

Because ' can also use for " in html. You can code like this in this case.

$msg = "<div class='alert alert-info alert-login'>login failed<br></div>";

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.