Page 1 of 1

PHP if/else statements

PostPosted: 12. December 2006 04:04
by codyjfisher
I'm using Windows XP SP2 and the latest version of XAMPP. I can't get any PHP "if / else statements" to work. Can somebody please help?

PostPosted: 12. December 2006 07:15
by Wiedmann
Then your code is wrong...

PostPosted: 12. December 2006 14:24
by codyjfisher
My code works on my web server. I've created CMS backends and complete PHP sites, I'm not sure how wrong it could be. One of my friends also had this problem with XAMPP for Windows but it works on his Mac with the same code.

I can't even get the simplest code like this to work:
Code: Select all
<?
if ($x == "about") { echo "About"; }
?>

PostPosted: 12. December 2006 17:15
by Wiedmann
Well, this code is wrong. You are using an undefinded variable in your condition.

With a higher error_reporting level, PHP will report this to you.

With your current (lower) error_reporting level you get no error message, your variable is set to NULL and the condition is allways FALSE --> you have no output from the if-part.

PostPosted: 12. December 2006 19:27
by codyjfisher
Yeah i know, that's just the code that fails. I define the variable earlier in the document.

PostPosted: 12. December 2006 23:34
by Wiedmann
I define the variable earlier in the document.

I don't see this in your sample.

Please post a compete example to reproduce your problem.

PostPosted: 13. December 2006 00:03
by codyjfisher
Code: Select all
<div class="navigation"><a href="?p=home">Home</a>&nbsp;&middot;&nbsp;<a href="?p=about">About</a>&nbsp;&middot;&nbsp;<a href="?p=sitebase">Sitebase</a>&nbsp;&middot;&nbsp;<a href="?p=portfolio">Portfolio</a>&nbsp;&middot;&nbsp;<a href="?p=communicate">Communicate</a></div>
<div class="content">

<?
if (isset($p)) {
$page_path = "pages/$p.php";
if (file_exists($page_path)) { include "$page_path"; }
else { include "pages/404.php"; }
}
else { include "pages/home.php"; }
?>

</div>


There's my code. It has worked fine in my last years of programming, on an actual web server with the most updated software.

PostPosted: 13. December 2006 01:06
by Wiedmann
Same problem as before... This cannot be the complete code:
- where did you define the variable $p?
- where did you define the variable $page_path?
- the HTML markup is not complete.