0

Hello everyone, I got an error from the code which I am copy-pasting from a textbook. Could you please tell me what I am doing wrong?

Here are the codes:
login.php:

<?php
session_unset();
?>
<html>
<head>
<title>Please Log In</title>
</head>
<body>
<form method"post" action="http://localhost/movie1.php">
<p>Enter your username:
<input type="text" name="user">
</p>
<p>Enter your password:
<input type="password" name="pass">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>

movie1.php:

<?php
//delete this line setcookie('username', 'Joe', time()+60);
session_start();
$_SESSION['username']=$_POST['user'];
$_SESSION['userpass']=$_POST['pass'];
$_SESSION['authuser']=0;
//Check username and password information
if (($_SESSION['username']== 'Joe') AND
($_SESSION['userpass']== '12345'))
{
$_SESSION['authuser']=1;
}
else
{
echo "Sorry, but you don’t have permission to view this
page, you loser!";
exit();
}
?>
<HTML>
<HEAD>
<TITLE>Find my Favorite Movie!</TITLE>
</HEAD>
<BODY>
<?php
$myfavmovie=urlencode("Life of Brian");
echo "<a href='http://localhost/moviesite.php?favmovie=$myfavmovie'>";
echo "Click here to see information about my favorite movie!";
echo "</a>";
?>
</BODY>
</HTML>

When I am entering username:Joe and password:12345 I get the following result:

Notice: Undefined index: user in C:\xampp\test\movie1.php on line 4

Notice: Undefined index: pass in C:\xampp\test\movie1.php on line 5
Sorry, but you don’t have permission to view this page, you loser!

Could you please tell me what I am doing wrong and how can I fix this?
Thank you very much

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by newbiecoder
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.