How do i get data from a database and put it in a session variable using php?

william

New member
I have got a login system on my website it is a html that when submited goes to a php check page and put all info into the session. I need to put more info from a databse into a session variable so i dont have to connect to the database on the members page, This is my check login page :
<?php
$host="localhost";
$username="";
$password="";
$db_name="";
$tbl_name="members";


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");
session_register("mypassword");
header("location:members.php");
}
else {
echo "Wrong Username or Password";
}
?>
I have taken out the username and password for security, i want it to take the rank section in my database table members for the person who is logging in and put it in a session variable.
I hope i am making sense, if not very sorry i am learing php.
Thanks
William
 
Back
Top