Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Undefined index error

Status
Not open for further replies.

may1hem

Programmer
Joined
Jul 28, 2002
Messages
262
Location
GB
Hi, I'm just starting up with PHP and am trying to figure out why the below code works on my friend's computer and doesn't work on mine.

I've set up a new Web site on IIS on Windows 2000 Server and I'm running PHP4.3.3.

When I run the code below I receive this error:
"Notice: Undefined variable: p in C:\temp\my web site\index.php on line 10

Notice: Undefined index: in C:\temp\my web site\index.php on line 10"

Any ideas what is going wrong here?

Thanks,
May

----------------------
<html>
<head>
<title>My Web Site</title>
</head>
<?

$pages['1'] = '01_1_home.php';
if (!$pages[$p]) {$p = array_shift(array_keys($pages));}

?>
<frameset rows="*" cols="134,*" frameborder="NO" border="0" framespacing="0">
<frame src="nav_1.php?s=1&p=<?=$p?>" name="leftFrame" scrolling="NO" noresize>
<frameset rows="206,*" cols="*" framespacing="0" frameborder="NO" border="0">
<frame src="top_01.php" name="topFrame" scrolling="NO" noresize>
<frame src="<?=$pages[$p]?>" name="mainFrame">
</frameset>
</frameset>
</html>
 
May,

Try defining your array like this:

$pages = array(1 => '01_1_home.php');

... and see if that helps! Haven't got time to test it myself right now.

Good Luck §:O)


Jakob
 
1. I think it's actually good for a beginner to have the error reporting set that you notice things like the uninitialized variable.
Where does $p come from? If you pass it with GET or POST read the chapter about register_globals inb the PHP manual.
2. Error #2 comes out of #1. An array with an uninitialized offset/key produced that error.

Also be aware that there's a difference between $myArray[1] and $myArray['1']. The first is the offset 1 (the second element of the array), the second example is an associative array key.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top