Pieter Lategan Posted June 23, 2011 Share Posted June 23, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/240213-session-error-on-lines-5-and-6/ Share on other sites More sharing options...
fugix Posted June 23, 2011 Share Posted June 23, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/240213-session-error-on-lines-5-and-6/#findComment-1233877 Share on other sites More sharing options...
Pikachu2000 Posted June 23, 2011 Share Posted June 23, 2011 When posting code, enclose it within the forum's . . . BBCode tags. Quote Link to comment https://forums.phpfreaks.com/topic/240213-session-error-on-lines-5-and-6/#findComment-1233878 Share on other sites More sharing options...
Pieter Lategan Posted June 23, 2011 Author Share Posted June 23, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/240213-session-error-on-lines-5-and-6/#findComment-1233883 Share on other sites More sharing options...
fugix Posted June 23, 2011 Share Posted June 23, 2011 I'm assuming that you are trying to use the session values from above without them having any value. What does a print_r($_SESSION) show? Quote Link to comment https://forums.phpfreaks.com/topic/240213-session-error-on-lines-5-and-6/#findComment-1233886 Share on other sites More sharing options...
Pieter Lategan Posted June 23, 2011 Author Share Posted June 23, 2011 Sorry I am very new in this I dont understand you. I started studying last week , so I think you will understand that this is totaly different for me[/code} Quote Link to comment https://forums.phpfreaks.com/topic/240213-session-error-on-lines-5-and-6/#findComment-1233909 Share on other sites More sharing options...
fugix Posted June 23, 2011 Share Posted June 23, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/240213-session-error-on-lines-5-and-6/#findComment-1233949 Share on other sites More sharing options...
Pieter Lategan Posted June 23, 2011 Author Share Posted June 23, 2011 I got it work thank you so much for your help!!!! Quote Link to comment https://forums.phpfreaks.com/topic/240213-session-error-on-lines-5-and-6/#findComment-1233956 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.