Question

I want to do login page. When I enter details, issue is appeared.

Login.php

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

movie1.php

<?php
session_start();
$_SESSION['username'] = $_POST['user'];
$_SESSION['userpass'] = $_POST['pass'];
$_SESSION['authuser'] = 0;
if (($_SESSION['username'] == 'Joe') and ($_SESSION['userpass'] == '12345'))
{
$_SESSION ['authuser']=1;
}
else {
echo 'you can not enter here.';
exit ();
}

?>

<html>

<?php
$myfavmovie = urlencode ('Life of brain');
echo "<a href=\"moviesite.php?favmovie=$myfavmovie\">";
echo "click here for more information";
echo "</a>"; 
?>

</html>

When I try login user name: Joe and password: 12345. I will get error. Notice: Undefined index: pass in C:\xampp\htdocs\book\book\movie1.php on line 4 My PHP version is 5.4.7.

moviesite.php

<?php
session_start();
if ($_SESSION['authuser'] != 1)
{echo "you don't enter here.";
exit();
}

?>
<html>
<head >
<title > My Movie Site - <?php echo $_GET['favmovie']; ?> </title>
</head >
<?php 
echo "welcome our website, " ;
echo $_SESSION['username'];
echo "."."<br>";
echo "my favorite film is ";
echo $_GET['favmovie'];
echo "<br>";
$movierate= 5;
echo "my point is"." ".$movierate;

?>
</html>
Was it helpful?

Solution

Change,

<input type="password" name "pass"/></p>

to

<input type="password" name="pass"/></p>

Because of the invalid HTML Markup (missing =), PHP won't see the input "pass". So it won't appear in the $_POST array, so it's giving you an undefined index error because you're trying to reference something that doesn't exist.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top