ra_ie_darkness Posted November 8, 2011 Share Posted November 8, 2011 I'm using xampp and am trying to create a login session...these are the my php files login.php <form action='login1.php' method='post'> Email: <input type='text' name='id'></br> Pass : <input type='password' name='pass'></br> <input type='submit' name='login' value='login'> login1.php <?php $id=$_POST['id']; $pass=$_POST['pass']; $conn=mysql_connect("localhost","root",""); if (!$conn) { die('Could not connect: ' . mysql_error()); } $e=mysql_select_db('test', $conn); if(!$e) { die(''.mysql_error()); } else { echo 'database selected successfully'; } $sql=mysql_query("Select email,password from login where email='$id' AND password='$pass'"); $count=mysql_num_rows($sql); if($count==1) { session_start(); echo "</br>Login Successful</br>"; echo "Please wait 5 seconds "; /* redirct to the specified page */ header("refresh:5;url=empty.php"); } else { echo "please try to login again</br>"; echo "you will be redirected to the login page in 5 seconds"; /* redirct to the specified page */ header("refresh:5;url=login.php"); } mysql_close(); ?> empty.php <?php session_start(); $logi=$_SESSION['id']; echo 'welcome '.$logi; ?> empty.php is supposed to display the email id from login.php I checked it about an hour ago and it was working fine but now it gives me an error Undefined index: id in C:\xampp\htdocs\littleprogress\empty.php on line 4 I didn't change anything after checking it. only cleared the history and cookies of my firefox browser what could be the problem Quote Link to comment https://forums.phpfreaks.com/topic/250689-problem-with-session/ Share on other sites More sharing options...
KevinM1 Posted November 8, 2011 Share Posted November 8, 2011 Calling session_start in login.php isn't enough to send the value to empty.php. You need to explicitly assign it to a session variable: $_SESSION['id'] = $id; Quote Link to comment https://forums.phpfreaks.com/topic/250689-problem-with-session/#findComment-1286176 Share on other sites More sharing options...
ra_ie_darkness Posted November 8, 2011 Author Share Posted November 8, 2011 that worked thank you Quote Link to comment https://forums.phpfreaks.com/topic/250689-problem-with-session/#findComment-1286178 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.