-2

I wrote PHP in HTML code :

<div id="loginContainer">
<?php
if(!$_SESSION['id_client']){
  print "<a href=\"#\" id=\"loginButton\">";
} else {
  print "<a href=\"#\" id=\"loginButton3\">";
}
?>
</a></div>

but this appears in the output page: ;}else { print

How can I get the PHP to execute?

6
  • 6
    Does the page have a .php extension? Commented Jul 11, 2013 at 23:32
  • 1
    Just a tip, it would be much easier on you to keep track of quotes if you surrounded the strings in single quotes, so you wouldn't have to escape double quotes inside the string and possibly make a mistake sometimes. Commented Jul 11, 2013 at 23:33
  • This question just asked may help you also stackoverflow.com/questions/17604336/… Commented Jul 11, 2013 at 23:34
  • 2
    This could be better written as <a href="#" id="<?php echo $_SESSION['id_client'] ? "loginButton3" : "loginButton" ?>"></a> Commented Jul 11, 2013 at 23:34
  • @AndréDion I hate it when people moan about 1 line if statements saying they harder to read! Tidy code! Commented Jul 11, 2013 at 23:36

1 Answer 1

3

Does your file have a .php extension (or is your server configured to process that file as PHP)?

If not, the entire block:

<?php
if(!$_SESSION['id_client'])
{
print "<a href=\"#\" id=\"loginButton\">

Is being treated as one big, ugly, invalid HTML tag, leaving the rest to be visible.

Make sure the file has a .php extension.

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

2 Comments

Thank's , the file was .html ( problem solved )
is there an yway to run php in .html ????

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.