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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.