Ok I am trying to retrieave level from the database but I don't know how. I have a level session and I have it to echo it but I don't know how to get the level of each user because I don't know how to retrieve a users level. Do you? If so... <?php session_start(); include("config.php"); $username=$_POST['username']; $password=$_POST['password']; $result = mysql_query("SELECT * FROM members WHERE username='$username' and password='$password'") or die(mysql_error()); $result3=mysql_query($result); $count=mysql_num_rows($result); if($count==1){ if($level==1){} $_SESSION['username'] = "$username"; $_SESSION['password'] = "$password"; $_SESSION['level'] = "$level"; header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ?> PHP: But on the login success page it's empty, when it should be whatever I typed in in phpmyadmin. Please help. Thanks
session_start(); include("config.php"); $username=$_POST['username']; $password=$_POST['password']; $query = "SELECT * FROM members WHERE username='$username' and password='$password'"; if($result = mysql_query($query) or die(mysql_error())){ if(is_resource($result)){ if(mysql_num_rows($result) > 0){ $row = mysql_fetch_array($result); if($row['level'] == 1){ $_SESSION['username'] = $username; $_SESSION['password'] = $password; //? $_SESSION['level'] = $row['level']; header("location:login_success.php"); } }else{ echo "wrong username or password"; } } } PHP:
Ok theres no errors but it's like it won't redirect you to login_success or wrong password. Anyways I'm trying to get it right too so you're not the only one
No it doesn't. It stays at checklogin.php and never gives you "Wrong Username or Password" and never redirects you to login_success.php Here lemme give you the full codes. checklogin.php (What you gave me) session_start(); include("config.php"); $username=$_POST['username']; $password=$_POST['password']; $query = "SELECT * FROM members WHERE username='$username' and password='$password'"; if($result = mysql_query($query) or die(mysql_error())){ if(is_resource($result)){ if(mysql_num_rows($result) > 0){ $row = mysql_fetch_array($result); if($row['level'] == 1){ $_SESSION['username'] = $username; $_SESSION['password'] = $password; //? $_SESSION['level'] = $row['level']; header("location:login_success.php"); } }else{ echo "wrong username or password"; } } } PHP: login_success.php <?php session_start(); require("config.php"); if(!session_is_registered(user)){ echo $_SESSION['username']; } ?><?php if(!session_is_registered(level)){ echo $_SESSION['level']; } ?> PHP: adduser.php <?php // Make sure a form with the name username and password are created. // Include some necesarry files. include('config.php'); // Grab some variables $Username = mysql_real_escape_string($_POST['username']); $Password = mysql_real_escape_string($_POST['password']); $Password_Encrypted = md5($Password); // Setup Query $Query = "INSERT INTO `members` (`id`, `username`, `password`) VALUES (NULL, '$Username', '$Password_Encrypted')"; // Execute Query mysql_query'($Query)' or die mysql_query(); // Check if query did get inserted $Query_Check = mysql_affected_rows(); if($Query_Check == 1) { $_SESSION['username'] = "$username"; // The , used below are to keep the echo fluid and is often required and used in much more professional scripts. echo 'User ', $_SESSION['username'], ' was Inserted into database, Session Set.'; } else { echo 'FAILURE!!!'; } ?> PHP: login.php <?php session_start(); ?><form name="login" id="name" action="checklogin.php" method="post"> Username: <input name="username" type="text" id="username"> <br> Password: <input name="password" type="text" id="password"> <input type="submit"> Code (markup):
Thanks but that's not the prob. The prob is checklogin.php Let me make it more cleaer. In checklogin.php I need it to check the level from the database of whatever user. If I'm the admin the level should be 1. So admin levels are 1. When I click submit on login.php it will go to checklogin.php and checklogin.php checks the username, passwor and level. If the username and password are right it'll go to login_succes.php if it's wrong it should say "Wrong Username / Password" and while it's checking the username and password it should check the level of the user and then on login_success.php it should say your level is whatever level the user is. You get it now?
I think you need to add a filed level to your members table, and when you add new member to your members table you need to add username,password and level.
I already have that stuff. All I need is checklogin.php to just simply retrieve the level of that user. Do you have a sample?
best way give me hosting details let me sort this for u U can change pass after that If its on local server I am helpless Regards Alex
Perfect BUT I don't know if it's retrieveing the level. So in login_success.php I need it to echo the level. But I don't really know how exactly.
I don't know where you trying to retrieve your level from. also your password is encripted with md5 function, which mean you need to compare your password like this $username=$_POST['username']; $password=md5($_POST['password']); "SELECT * FROM members WHERE username='$username' and password='$password'";
echo $row['level']; Add this and refresh Regards Alex yes u r not encrypting password as ur adduser says u r encrypting pass so pass comparisons will allways be wrong Regards Alex