4 Replies - 412 Views - Last Post: 20 August 2009 - 08:20 AM Rate Topic: -----

#1 neos300  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 62
  • Joined: 21-April 09

Is this viable php?

Post icon  Posted 20 August 2009 - 06:56 AM

<?php
<p>Hai</p>
?>



So would this code not return an error?
Is This A Good Question/Topic? 0
  • +

Replies To: Is this viable php?

#2 tommyflint  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 34
  • View blog
  • Posts: 679
  • Joined: 24-July 08

Re: Is this viable php?

Posted 20 August 2009 - 07:04 AM

Yes that code is perfectly viable with echo before the html
However there is no need to put it in PHP tags

tommyflint

This post has been edited by tommyflint: 20 August 2009 - 08:28 AM

Was This Post Helpful? 0
  • +
  • -

#3 neos300  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 62
  • Joined: 21-April 09

Re: Is this viable php?

Posted 20 August 2009 - 07:07 AM

What i mean is, i was trying to do this:
<?php
if($_SESSION['loggedin'] = true)
{
<p>Hai</p>
}
else
{
<p>yo</p>
}


This post has been edited by neos300: 20 August 2009 - 07:07 AM

Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5951
  • View blog
  • Posts: 23,214
  • Joined: 23-August 08

Re: Is this viable php?

Posted 20 August 2009 - 07:09 AM

This:
if($_SESSION['loggedin'] = true)
is not a comparison, but an assignment.
Was This Post Helpful? 0
  • +
  • -

#5 AdaHacker  Icon User is offline

  • Resident Curmudgeon

Reputation: 452
  • View blog
  • Posts: 811
  • Joined: 17-June 08

Re: Is this viable php?

Posted 20 August 2009 - 08:20 AM

Yes and no. Yes, you can do that, but no, the exact code you posted is not valid. You need to escape out of the <?php ?> block to write out literal HTML like that. For example:
<?php
if($_SESSION['loggedin'] == true) {
?>
<p>Hai</p>
<?php
} else {
?>
<p>yo</p>
<?php
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1