LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to intersperse PHP with HTML (https://www.linuxquestions.org/questions/programming-9/how-to-intersperse-php-with-html-832091/)

resetreset 09-14-2010 09:49 AM

How to intersperse PHP with HTML
 
Hi,
I have a site which will have, for example, a login system where people have to enter their usernames and passwords, depending on which they'll be let in to the site. So, in code, I've got a line like:

if ($_POST['password'] == $password) {
then do whatever
}
else { print "Wrong password" ; )

My problem is, this "Wrong password" printing is just a solitary line, not keeping with the colours and style of the site, and it looks very bad. I want to ideally, output some HTML, which will have a picture, and print the "Wrong password" in the font and colours I desire. How do I do this? Do I have to put all the HTML in a print statement, and then deal with the nightmare of escaping all the quote marks in it with a "\"? Or is there a cleaner method to the whole thing? Maybe something like this -

if ($_POST['password'] == $password) {
then do whatever
}
else
?>

<FONT SIZE=2> Wrong password </FONT>


Thanks for your help.

14moose 09-14-2010 09:54 AM

Hi -

One possibility:
Code:

<?php
if ($_POST['password'] == $password) {
  ... then do whatever ...
}
else {
  echo "Wrong password";
}
 ?>

Another possibility:
Code:

<?php
if ($_POST['password'] == $password) {
  ... then do whatever ...
}
else ?>
<em>Wrong password</em>
<?php
  ... more PHP ...

PS:
Don't use "<FONT>" tags, if you can avoid it. IMHO, CSS is much better...

resetreset 09-14-2010 10:03 AM

Aah so I was right then, in my 2nd snip of code....? :) Thanks a lot, 14moose. Anybody else got any comments?

graemef 09-14-2010 06:51 PM

You can include (or require) a file which holds the html formatting that you desire.

rsciw 09-15-2010 10:29 AM

Quote:

Originally Posted by 14moose (Post 4097179)
Hi -

One possibility:
Code:

<?php
if ($_POST['password'] == $password) {
  ... then do whatever ...
}
else {
  echo "Wrong password";
}
 ?>

Another possibility:
Code:

<?php
if ($_POST['password'] == $password) {
  ... then do whatever ...
}
else ?>
<em>Wrong password</em>
<?php
  ... more PHP ...

PS:
Don't use "<FONT>" tags, if you can avoid it. IMHO, CSS is much better...

Personally I never liked interrupting the
<?php ?> code for HTML code, hence I usually write this way, which is a 3rd option to do :)

Code:

<?php
if ($_POST['password'] == $password) {
  ... then do whatever ...
}
else
print "<em>Wrong password</em>";
//  ... more PHP ...



All times are GMT -5. The time now is 07:09 PM.