Error in Sessions

Hi, maybe this is just very easy for you guys but its kinda problematic to me as I am new in php, but I was getting this error of undefined index in the session variable every time the variable is empty. I already put if else statement. The flow is like this, I want that status div will show a link of login and register here when the user in not logged in, but if it does then the status area must show the username of the logged in user as a link to access its profile. Please, help me. Still starting so I'm still expecting more questions later. Thanks in advance. God Bless.

Hey friend , that is because your session variable have no result of value Try this Database MySQL admin table columns id, username, passcode. CREATE TABLE admin ( id INT PRIMARY KEY AUTO_ INCREMENT, username VARCHAR(30) UNIQUE, passcode VARCHAR(30) ); Config.php Database configuration file. Login.php Contains PHP and HTML code. >?php include("config.php"); session_start(); if($_SERVER["REQUEST_ METHOD"] == "POST") { // username and password sent from Form $myusername=addslashes($_ POST['username']); $mypassword=addslashes($_POST ['password']); $sql="SELECT id FROM admin WHERE username='$ myusername' and passcode='$ mypassword'"; $result=mysql_query($sql); $row=mysql_fetch_array($result); $active=$row['active']; $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1) { session_register("myusername"); $_SESSION['login_user']=$ myusername; header("location: welcome.php"); } else { $error="Your Login Name or Password is invalid"; } } ?>



lock.php Session verification. If no session value page redirect to login.php

Add new comment