i have some problems with the following code: <html> <head> <title>Session Page</title> </head> <body> <?php session_start(); //start session $user=$_POST['username']; $pass=$_POST['password']; $submit=$_POST['submit']; if($user&&$pass==false){ echo "please login"; } if(isset($_SESSION['loginUser']) && isset($_SESSION['loginPass'])){ $_SESSION['loginUser']=$user; $_SESSION['loginPass']=$pass; $loginCheck=mysql_query("SELECT * FROM users WHERE username=$user"); $rowUser=mysql_query("SELECT username,password FROM users"); $num_rows=mysql_num_rows($rowUser); $result=mysql_result($loginCheck,$num_rows) or die(mysql_error()); if($result&&$submit){ //this is another part which seems to not be runned by the script echo "Welcome back ".$user.",log in succesfully"; }else{ echo "Login failed or fields not completed"; } } ?> </body> </html> PHP: also I get the following notices for the variables containing $_POST: Notice: Undefined index: username in C:\wamp\www\***\session.php on line 9 Notice: Undefined index: password in C:\wamp\www\***\session.php on line 10 Notice: Undefined index: submit in C:\wamp\www\***\session.php on line 11
First of: Sesssion should be started at top of file BEFORE html tags. Second: To fix these Notices, do it like this <html> <head> <title>Session Page</title> </head> <body> <?php session_start(); //start session if (isset($_POST['submit']) { $user=$_POST['username']; $pass=$_POST['password']; $submit=$_POST['submit']; if($user&&$pass==false){ echo "please login"; } if(isset($_SESSION['loginUser']) && isset($_SESSION['loginPass'])){ $_SESSION['loginUser']=$user; $_SESSION['loginPass']=$pass; $loginCheck=mysql_query("SELECT * FROM users WHERE username=$user"); $rowUser=mysql_query("SELECT username,password FROM users"); $num_rows=mysql_num_rows($rowUser); $result=mysql_result($loginCheck,$num_rows) or die(mysql_error()); if($result&&$submit){ //this is another part which seems to not be runned by the script echo "Welcome back ".$user.",log in succesfully"; }else{ echo "Login failed or fields not completed"; } } } ?> </body> </html> PHP: Third: You are not connected into database Fourth: this line: $result=mysql_result($loginCheck,$num_rows) or die(mysql_error()); gives you only last user from that table (if you have more than one, it will throw you warning)