Jump to content

Recommended Posts

Hi

 

I got the erros on lines 5 and 6 and cant understand what the problem is.  Can someone please give me abit of advise.

 

Thanks a lot

 

Pieter

 

<?php

session_start();

$_SESSION['username'] = $_POST['user'];  //Undefined index: user in C:\wamp\www\chapter2\movie1.php on line 5
$_SESSION['userpass'] = $_POST['pass'];  //Undefined index: pass in C:\wamp\www\chapter2\movie1.php on line 6
$_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>My Movie Site </title>
</head>
<body>
<?php include "header.php"; ?>
<?php 
$myfavmovie = urlencode("Life of Brian");
echo "<a href='p39.php?favmovie=$myfavmovie'>";
echo "Click here to see information about my favorite movie!";
echo "/a";
echo "<br>";
echo "<a href= 'moviestie.php?movienu=5'>";
echo "Click here to see my top 5 movies.";
echo "<br>";
echo "<a href='mviesite.php?movienum=10'>";
echo "Click here to see my top 10 movies.";
echo "</a>"

?>


</body>
</html>

 

MOD EDIT: code tags added.

Link to comment
https://forums.phpfreaks.com/topic/240213-session-error-on-lines-5-and-6/
Share on other sites

I'm assuming that your two $_POST indices are what's causing the E_NOTICE

Most likely this notice is being triggered because your form has not been submitted yet, therefore there are no $_POST indices to send. This notice can be avoided by using the isset() function to check for the post values first. E.g.

if (isset($_POST['user']))
{
// set your session variable
}

you can do the same for you other post value

 

 

Thank you I move a bit, but now get this error

Welcome to our site,

Notice: Undefined index: username in C:\wamp\www\chapter2\p39.php on line 20

!

My favorite movie is

Notice: Undefined index: favmovie in C:\wamp\www\chapter2\p39.php on line 23

 

My movie rating for this movie is : 5 

 

Can you maybe help me with this?

No problem, basically, you are trying to use sessions that do not have values. Which will cause an undefined index error that you received. The way your code is now, your sessions will only be able to be called after your $_POST datahas been sent, thus setting the values od your sessions yo that data.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.