session is not working
Posted: Tue Dec 22, 2009 6:43 pm
friends,
i've just started learning PHP.
I'm stuck on session. i tried my best on internet but writing is now the last option for me.
Login.php
i've checked login.php is connecting mysql and works fine.
products.php
i'm actually trying to provide access to product page only if visitor comes from login.php.
i'm getting error "Notice: Undefined index: uid in C:\wamp\www\Practice\Login_and_MySql\products.php on line 6" if i come from login.php.
kindly help me.
i've just started learning PHP.
I'm stuck on session. i tried my best on internet but writing is now the last option for me.
Login.php
Code: Select all
<html>
<body>
<?php
if(isset($_POST['btnSubmit'])=="Login") {
$user=$_POST['txtUser'];
$password=$_POST['txtPassword'];
$con=mysql_connect("localhost","root","") or die ("error connection");
mysql_select_db("imran",$con) or die ("database not connect");
$qryLogin="SELECT * FROM login where username='$user' AND password='$password'";
$qryExecute=mysql_query($qryLogin);
$qryRow=mysql_fetch_array($qryExecute);
if($qryRow!=NULL){
$_SESSION['uid']=$qryRow['username'];
echo $_SESSION['uid'];
header('Location: products.php');}
else{ echo "not login"; }
}
?>
<form name="loginForm" action="" method="post">
Id: <input type="text" name="txtUser" /><br />
Password: <input type="text" name="txtPassword" /><br />
<input type="submit" name="btnSubmit" value="Login" />
</form>
</body>
</html>
products.php
Code: Select all
<html>
<body>
<?php
session_start();
$uuid=$_SESSION['uid'];
echo $uuid;
?>
</body>
</html>
i'm getting error "Notice: Undefined index: uid in C:\wamp\www\Practice\Login_and_MySql\products.php on line 6" if i come from login.php.
kindly help me.