Jump to content

need help with php login


dezkit

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/186879-need-help-with-php-login/
Share on other sites

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'];

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.