Undefined index

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
crash69uk
Forum Newbie
Posts: 1
Joined: Mon May 31, 2004 5:16 am

Undefined index

Post by crash69uk »

Hey,
I'm pretty new to php, and having a few problems.

<?php
session_start();
$_SESSION['username']= "Joe123245";
$_SESSION['authuser']= 1;
?>
<html>
<head>
<title>
Find my favourite movie
</title>
</head>
<body>
<?php
$myfavmovie=urlencode("Life of brian");
echo "<a href='http://localhost/moviesite2.php?favmovie=$myfavmovie'>";
echo "Click here to see information about my favorite movie!";
echo "</a>";
?>
</body>
</html>

<?php
session_start();
?>
<html>
<head>
<title>My Movie site - <?php echo $_REQUEST['favmovie']?></title>
</head>
<body>
<?php
echo "Welcome to our site, ";
echo $_SESSION['username'];
echo "<br>";
echo "My favourite movie is ";
echo $_REQUEST['favmovie'];
echo "<br>";
$movierating = 5;
echo "My movie rating for this movie is";
echo $movierating;
?>
</body>
</html>

This should be nice and simple and i swear i had this working last night but now i get

Welcome to our site,
Notice: Undefined index: username in C:\Apache2\WWW\localhost\moviesite2.php on line 11

My favourite movie is Life of brian
My movie rating for this movie is5

I'm kind of guessing i've installed something wrong as the code is pretty damn simple,

cheers
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Post by Heavy »

Hello.
I assume what what you have is two different files?

If that notice message is the only message you got, I am curious if just browsing the upper file before the latter would solve your problem.

I don't see why it shouldn't work. If you had warnings about session not started, I would have guessed you had some line or space characters before the first <?php, but you seem to do it right.

:!:
Idea:

Try a decent browser caching buster:

Code: Select all

<?php 

header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
session_start();
//blah blah
?>
Moreover, maybe a browser better suitable for web development than Internet Explorer would be something for you?
Daddy ususally has caching problems using IE. Try mozilla firefox if you can.

Tip:
Try using the php syntax highlighter when you post your examples. The rightmost button under the subject text input.
Post Reply