PHP if/else statements

Problems with the Windows version of XAMPP, questions, comments, and anything related.

PHP if/else statements

Postby codyjfisher » 12. December 2006 04:04

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?
codyjfisher
 
Posts: 4
Joined: 12. December 2006 02:51

Postby Wiedmann » 12. December 2006 07:15

Then your code is wrong...
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby codyjfisher » 12. December 2006 14:24

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"; }
?>
codyjfisher
 
Posts: 4
Joined: 12. December 2006 02:51

Postby Wiedmann » 12. December 2006 17:15

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.
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby codyjfisher » 12. December 2006 19:27

Yeah i know, that's just the code that fails. I define the variable earlier in the document.
codyjfisher
 
Posts: 4
Joined: 12. December 2006 02:51

Postby Wiedmann » 12. December 2006 23:34

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.
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby codyjfisher » 13. December 2006 00:03

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.
codyjfisher
 
Posts: 4
Joined: 12. December 2006 02:51

Postby Wiedmann » 13. December 2006 01:06

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.
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 143 guests