Forum Moderators: coopster

Message Too Old, No Replies

If statment?

         

olokiop

1:50 am on Feb 2, 2005 (gmt 0)

10+ Year Member



When I pull this via a browser I get all the text outputed below the links. I have tried several options in the if statments (then, else, elseif) but I still get the text from all the conditions. Anyone care to take a crack at it?

///////test.php//////////

<html>
<head><title></title></head>

<body>
<a href="<?php echo $PHP_SELF;?>?home=1">Home</a>&nbsp;&nbsp;&nbsp;
<a href="<?php echo $PHP_SELF;?>?about=1">About/Contact Us</a>&nbsp;&nbsp;&nbsp;
<a href="<?php echo $PHP_SELF;?>?products=1">Products</a>&nbsp;&nbsp;&nbsp;
<a href="<?php echo $PHP_SELF;?>?services=1">Services</a>&nbsp;&nbsp;&nbsp;
<a href="<?php echo $PHP_SELF;?>?repair=1">Repair</a>&nbsp;&nbsp;&nbsp;
<a href="<?php echo $PHP_SELF;?>?network=1">Network</a>&nbsp;&nbsp;&nbsp;
<br><br><br>
<?php
if ($_GET['home'] = '1') {
?>

Only This text SHOULD show if you clicked on Home.

<?php
}
if ($_Get['about'] = '1') {
?>

Only This text SHOULD show if you clicked on About Us.

<?php
}
if ($_Get['products'] = '1') {
?>

Only This text SHOULD show if you clicked on Products.

<?php
}
if ($_Get['services'] = '1') {
?>

Only This text SHOULD show if you clicked on Services.

<?php
}
if ($_Get['repair'] = '1') {
?>

Only This text SHOULD show if you clicked on Repair.

<?php
}
if ($_Get['network'] = '1') {
?>

Only This text SHOULD show if you clicked on Network.

<?php
}
?>

//End of Document//

</body>
</html>

HughMungus

1:59 am on Feb 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think you're missing double == signs (required for if statements).

RedAndy

2:27 am on Feb 2, 2005 (gmt 0)

10+ Year Member



Hi,

Hugh's post should solve your problem.

However, $PHP_SELF is deprecated and has been replaced with $_SERVER['PHP_SELF']. I would probably have opted for a slightly different style of coding - something more like
?page=home
?page=repair
...

and then have performed a switch/elseif on the variable $home, having already checked that the var exists.

$page=(isset($_GET['page']))?$_GET['page']:'gah';

hth

Andy

olokiop

3:02 am on Feb 2, 2005 (gmt 0)

10+ Year Member



It did! thanks for the info.

I am a little confused on the $page statement.

Would you mind dissecting it?

olokiop

5:31 am on Feb 2, 2005 (gmt 0)

10+ Year Member



AH HA! Got it working =)
Thank you again for the help!

RedAndy

6:41 am on Feb 2, 2005 (gmt 0)

10+ Year Member



sorry, that should have read "switch/elseif on the variable $page" not $home. Way to confuse someone, I previewed it too :( Glad you got it going!

coopster

12:56 pm on Feb 2, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, RedAndy.

No worries, we all make mistakes ;)