Page 1 of 1

else if?

Posted: Tue Feb 17, 2004 11:29 am
by defx
For some reason I think the problem with my script is the else if statement. Is it? If not, could someone tell me what exactly is wrong? I keep getting the message Notice: Use of undefined constant about - assumed 'about'.

Code: Select all

<?php
$p=$_GET['p']; 

if ($p == "news") { 

include ('news.txt');

} elseif ($p = about) {

include ('about.txt');

} elseif ($p = roster) {

include ('roster.txt');

} elseif ($p = schedule) {

include ('schedule.txt');

} elseif ($p = matches) {

include ('matches.txt');

} elseif ($p = downloads) {

include ('downloads.txt');

} elseif ($p = sponsors) {

include ('sponsors.txt');

}

?>

Posted: Tue Feb 17, 2004 11:32 am
by Illusionist
you did the first one right, $p == "news", but on all the others you didn't. Remember the = is the assingment operator, and then == is what you use to check if its equal. CHange all your = in your else if's and put quote around the text

Posted: Tue Feb 17, 2004 11:34 am
by Etherguy
You need some single qoutes around the word about for starters.

Code: Select all

<?php
 elseif ($p == 'about') {

?>
I would also throw in a second equal sign, or your elseif won't work properly.

Hope that helps.

Posted: Tue Feb 17, 2004 11:38 am
by defx
It almost works, but I still get the error

Notice: Undefined index: p in index.php on line 66

Posted: Tue Feb 17, 2004 11:40 am
by Illusionist
what is line 66? you ddin't include any line numbers earlier, so we can't jsut guess at what your doing wrong!

Posted: Tue Feb 17, 2004 11:53 am
by defx
line 66 is

Code: Select all

$p=$_GET&#1111;'p'];

Posted: Tue Feb 17, 2004 11:55 am
by Illusionist
are you sure your passing somethign through p?
and try spacing it out, $p = $_GET['p'];

Posted: Tue Feb 17, 2004 1:34 pm
by Draco_03
chek if you closed line 65 too (puting ";" at the end)

Posted: Tue Feb 17, 2004 1:38 pm
by liljester
in *any* comparision you have to use "==" if your checking for equality.. a single equals sign (=) is for asignment.

also are those supposed to be constants? or are they supposed to be strings?

Posted: Tue Feb 17, 2004 1:41 pm
by defx
ok I know why it says it, now it's just a matter of making it go away. The message is there because I was not setting the variable in the URL. So to try and make that go away I used

Code: Select all

} elseif (!isset($p)) {
echo ("variable not set");
}
so now, variable not set shows up, but so does the message, how do i make it go away?

here is the full code which i have now

Code: Select all

$p = $_GET['p']; 	
		
		if (!isset($p)) {
		echo ("variable not set");
	
		} elseif ($p == "news") { 
			include ('news.txt');
	
		} elseif ($p == 'about') {
			include ('about.txt');
	
		} elseif ($p == 'roster') {
			include ('roster.txt');
	
		} elseif ($p == 'schedule') {
			include ('schedule.txt');
	
		} elseif ($p == 'matches') {
			include ('matches.txt');
	
		} elseif ($p == 'downloads') {
			include ('downloads.txt');
	
		} elseif ($p == 'sponsors') {
			include ('sponsors.txt');
			
		} else {
			echo ("test");
		}

Posted: Tue Feb 17, 2004 2:47 pm
by Weirdan

Code: Select all

$p = isset($_GET['p'])?$_GET['p']:'';     
       
      if (empty($p)) { 
      echo ("variable not set"); 
    
      } elseif ($p == "news") { 
         include ('news.txt');
//.................[skipped]........