Page 1 of 1

Help with syntax

Posted: Mon Feb 19, 2007 5:36 pm
by quadoc
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I've the following codes, all I wanted to do is to execute the HTML code when $an_mess not blank, but somehow I keep getting error messages.  Could someone tells me why? Thanks...

Code: Select all

<?php

  $mess = "this is a test";

  if ($mess != "")
   {  ?>
 
<html>   
   

<p >

 <? echo $an_mess; ?>  

</p>   
</body>   
</html>   

<? If ($mess != "") {echo "}"; }  ?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Feb 19, 2007 6:17 pm
by onion2k
Wow. That's really horrible. First thing to do is to rewrite the code so it's properly formatted in a tidy and readable way, then you'll be able to see what's wrong with it. As it happens, the last line of your script is what's breaking it, plus, if you want to echo everything when $an_mess isn't empty you really need to check it rather than checking $mess.

Code: Select all

<?php

$mess = "this is a test"; //I imagine this is meant to be $an_mess, otherwise your code will never echo anything because $mess is unset and will always be empty

if (!empty($an_mess)) { //empty() checks to see if a variable contains a value, !empty() checks to see if it's not empty. Better than $var!="".

?>
  <html>   
    <body>
      <p >
        <? echo $an_mess; ?> 
      </p>   
    </body>   
  </html>
<?php

} //Close the if statement.

?>

Posted: Tue Feb 20, 2007 12:55 pm
by quadoc
Wow! Thanks... You made it look so easy.... 8O

Posted: Tue Feb 20, 2007 2:16 pm
by RobertGonzalez
You are also referencing a variable that is never set in this snip of code.

Code: Select all

<?php
// You set $mess here...
$mess = "this is a test";

// You are checking $mess here (for empty)
if (empty($mess)): 
?>
<html>   
  <body>
    <!-- You are calling $an_mess here, but it is not set to anything as fas as I can see -->
    <p ><?php echo $an_mess; ?></p>
  </body>   
</html>   

<?php
// Close the if
endif;
?>