dezkit Posted January 1, 2010 Share Posted January 1, 2010 Hi, I have a problem, I want to echo what a user has in their access row in my mysql table, I can't seem to figure out the logic behind this. checklogin.php <?php mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ session_register("myusername"); header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ?> login_success.php <?php session_start(); if(!session_is_registered(myusername)){ header("location:index.php"); } ?> <html> <body> <?php echo $access ?> Login Successful <a href="./logout.php">Logout</a> </body> </html> When I log in and view login_success.php I cannot see access, which when I login it is supposed to say 1 Mysql table: id username password access 1 test test123 1 Please help me, thank you. Quote Link to comment Share on other sites More sharing options...
freeloader Posted January 1, 2010 Share Posted January 1, 2010 Not sure what you're trying to do there.... First of all, you have a syntax error on your second page (no semicolon after $access). Secondly, you're echo'ing an undeclared variable. You have to define $accesss before you can print it. Quote Link to comment Share on other sites More sharing options...
dezkit Posted January 1, 2010 Author Share Posted January 1, 2010 I want to echo the data that is assigned to the username that is inputted into the form, for example, id username password access 1 kevin pw123 1 When somebody logs in as kevin, they see the "1" after they log in. Quote Link to comment Share on other sites More sharing options...
blitz219 Posted January 2, 2010 Share Posted January 2, 2010 at the top of your script put session_start(); and to get the value stored in access column you can use this on you main page then store the $access variable in a session variable. $row=mysql_fetch_array($results); $access = $row['access']; $_SESSION['access'] = $access; then call it on the success page $access = $_SESSION['access']; Quote Link to comment Share on other sites More sharing options...
dezkit Posted January 2, 2010 Author Share Posted January 2, 2010 Does not work still. Quote Link to comment Share on other sites More sharing options...
dezkit Posted January 2, 2010 Author Share Posted January 2, 2010 Okay I figured that out, but how does I echo the access now? I have mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); mysql_query("SELECT * FROM $tbl_name WHERE username='$myusername'") or die(mysql_error()); echo $access; it does not work. Quote Link to comment Share on other sites More sharing options...
blitz219 Posted January 4, 2010 Share Posted January 4, 2010 on the page you are trying to echo it on do you have $access = $_SESSION['access']; Quote Link to comment 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.