Page 1 of 1

Just need some really basic help..

Posted: Tue May 20, 2003 12:37 pm
by Drachlen
Okay, im designing a webpage which has some links at the top that go to different parts of the page. One link would goto Index.php?p=News and one to Index.php?p=Join Ill be adding more but this is all i need for right now. Here is my code:

Code: Select all

<?php
$p = News

if($p == News) {
	echo
		 "&nbsp;&nbsp;&nbsp;&nbsp;NEWS";
    } else {

    }
if($p == Join) {
	echo
		 "&nbsp;&nbsp;&nbsp;&nbsp;JOIN";
    } else {

    }
?>
?>
But this is giving me an error.. What am i doing wrong with the if statements? And also, this PHP is placed in the middle of an HTML document where the text is suppost to show up, is that okay to do?

Re: Just need some really basic help..

Posted: Tue May 20, 2003 12:58 pm
by JPlush76

Code: Select all

<?php
// NEED TO ADD SEMICOLON AND QUOTES
$p = 'News';

// NEED TO PUT QUOTES AROUND THIS
if($p == 'News') {
	echo "NEWS";
    } else {

    }

// NEED QUOTES HERE TOO
if($p == 'Join') {
	echo "JOIN";
    } else {

    }
?>
try that

also you dont need all those else statments if you're keeping them empty

Posted: Tue May 20, 2003 12:59 pm
by twigletmac
First of all - if you get an error it makes it easier to diagnose if you post the text.

In this case however, it looks fairly simple - you need to put strings (text) into quotes and you forgot a semi-colon. Try:

Code: Select all

<?php 
// of course if you set $p to News then it can't possibly be Join
$p = 'News'; 

if($p == 'News') { 
   echo 'NEWS'; 
} elseif ($p == 'Join') { 
   echo 'JOIN'; 
}
?>
Mac