PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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...
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]
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.
<?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.
?>
<?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;
?>