Just need some really basic help..

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!

Moderator: General Moderators

Post Reply
Drachlen
Forum Contributor
Posts: 153
Joined: Fri Apr 25, 2003 1:16 am

Just need some really basic help..

Post 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?
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Re: Just need some really basic help..

Post 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
Last edited by JPlush76 on Tue May 20, 2003 1:01 pm, edited 1 time in total.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Post Reply