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
defx
Forum Commoner
Posts: 36 Joined: Mon Feb 16, 2004 11:50 pm
Location: Florida, USA
Post
by defx » Tue Feb 17, 2004 11:29 am
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');
}
?>
Last edited by
defx on Tue Feb 17, 2004 1:43 pm, edited 1 time in total.
Illusionist
Forum Regular
Posts: 903 Joined: Mon Jan 12, 2004 9:32 pm
Post
by Illusionist » Tue Feb 17, 2004 11:32 am
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
Etherguy
Forum Commoner
Posts: 70 Joined: Fri Nov 01, 2002 9:09 pm
Location: Long Island, New York
Post
by Etherguy » Tue Feb 17, 2004 11:34 am
You need some single qoutes around the word about for starters.
I would also throw in a second equal sign, or your elseif won't work properly.
Hope that helps.
defx
Forum Commoner
Posts: 36 Joined: Mon Feb 16, 2004 11:50 pm
Location: Florida, USA
Post
by defx » Tue Feb 17, 2004 11:38 am
It almost works, but I still get the error
Notice: Undefined index: p in index.php on line 66
Illusionist
Forum Regular
Posts: 903 Joined: Mon Jan 12, 2004 9:32 pm
Post
by Illusionist » Tue Feb 17, 2004 11:40 am
what is line 66? you ddin't include any line numbers earlier, so we can't jsut guess at what your doing wrong!
defx
Forum Commoner
Posts: 36 Joined: Mon Feb 16, 2004 11:50 pm
Location: Florida, USA
Post
by defx » Tue Feb 17, 2004 11:53 am
Illusionist
Forum Regular
Posts: 903 Joined: Mon Jan 12, 2004 9:32 pm
Post
by Illusionist » Tue Feb 17, 2004 11:55 am
are you sure your passing somethign through p?
and try spacing it out, $p = $_GET['p'];
Draco_03
Forum Regular
Posts: 577 Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada
Post
by Draco_03 » Tue Feb 17, 2004 1:34 pm
chek if you closed line 65 too (puting ";" at the end)
liljester
Forum Contributor
Posts: 400 Joined: Tue May 20, 2003 4:49 pm
Post
by liljester » Tue Feb 17, 2004 1:38 pm
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?
defx
Forum Commoner
Posts: 36 Joined: Mon Feb 16, 2004 11:50 pm
Location: Florida, USA
Post
by defx » Tue Feb 17, 2004 1:41 pm
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");
}
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Tue Feb 17, 2004 2:47 pm
Code: Select all
$p = isset($_GET['p'])?$_GET['p']:'';
if (empty($p)) {
echo ("variable not set");
} elseif ($p == "news") {
include ('news.txt');
//.................[skipped]........