a65 Posted January 5, 2013 Share Posted January 5, 2013 i am trying to go to admin_control.php from login.php through session but it is showing the result improper access of page html code is <html><form method="post" action="login.php"> <link type="test/css" rel="stylesheet" href="user_info.css"></style> <body><table border="1px"> <tr><td>username</td><td><input type=text name=myusername></td></tr> <tr><td>password</td><td><input type=password name=mypassword></td> <tr><td>type</td><td><select name=account_type> <option>admin</option> <option>normal</option></select></td></tr> <tr><td><input type=submit name=login></td><td><input type=reset name=reset></td></tr></table></body></html> php code is <?php session_start(); mysql_connect("localhost","root",""); mysql_select_db("bank_acount"); $var1=$_POST['myusername']; $var2=$_POST['mypassword']; $var3=$_POST['account_type']; $query="select * from user_info where username='".$var1."' and password='".$var2."' and account_type='".$var3."'"; $result=mysql_query($query); $row=mysql_fetch_assoc($result); $num=mysql_num_rows($result); $_SESSION['sname']=$row['username']; $_SESSION['spasswword']=$row['password']; $_SESSION['saccount_type']=$row['account_type']; if($num) { if($_SESSION['saccount_type']==admin) header("location:admin_control.php"); else if($var3==normal) { header("location:user_control.php"); } } else { header("location:normal_user_reg.html"); } ?> admin_contro.php is <?php session_start(); if(isset($_SESSION['sname']) && isset($_SESSION['spassword'])&& isset($_SESSION['saccount_type']) ) { mysql_connect("localhost","root",""); mysql_select_db("bank_acount"); $query="select * from user_info"; $result=mysql_query($query); ?> <div align="center"><table width="150px" border="1px"><tr><td bgcolor="red">admin_control</td></tr> <tr><td><a href="add_account.php">add account</a></td></tr> <tr><td><a href="allocate_amount.php">allocate amount</td></tr> <tr><td><a href="make_payment.php"> make payment</a></td></tr> <tr><td><a href="fund_transfer.php"> fund transfer</a></td></tr> <tr><td><a href="set_user_type.php"> set user</a></td></tr> </table></div> <?php } else echo("improper acccess of page"); ?> Link to comment https://forums.phpfreaks.com/topic/272735-problem-in-implementing-session/ Share on other sites More sharing options...
Andy123 Posted January 5, 2013 Share Posted January 5, 2013 In one of your scripts, you are using $_SESSION['spasswword'] and in the other, you are using $_SESSION['spassword']. Notice the spelling. Thus, your conditional statement evaluates to false because this session variable is not set. Link to comment https://forums.phpfreaks.com/topic/272735-problem-in-implementing-session/#findComment-1403475 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.