Hi, I'm looking for help with my sessions and table data So far I have 2 tables, one named: userlogin which contains log in information listed by 'user_id' my next table is called userinfo which at the moment just contains user name and address, again listed by 'user_id' Currently I have a log in page, and a home page. The log in page uses the information from the userlogin table to verify that the user has an account and they have entered the correct information. Now this is were it gets tricky, (for me at least) as on this homepage i'm trying to display the information from the userinfo table which relates to the user_id from the userlogin table, relating to their unique information. The purpose of this is to be able to display information for my clients, all without having hundreds of separate pages and having only one page, which displays the information based upon who has logged in. Here is my loginpage code
// Use session variable on this page. This function must put on the top of page.
session_start();
$_SESSION['userName'] = 'Root';
////// Login Section.
$Login=$_POST['Login'];
if($Login){ // If clicked on Login button.
$username=$_POST['username'];
$password=$_POST['password']; // Encrypt password with md5() function.
// Connect database.
//connect
$con = mysql_connect("*****","*****","*****");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
//datebase
mysql_select_db("*****, $con);
// Check matching of username and password.
$result=mysql_query("select * from userlogin where username='$username' and password='$password'");
if(mysql_num_rows($result)!='0'){ // If match.
session_register("username"); // Craete session username.
header("location:home.php"); // Re-direct to main.php
exit;
}else{ // If not match.
$message="--- Incorrect Username or Password ---";
}
} // End Login authorize check.
?>
and here is my homepage code.
<?php
session_start();
if(isset($_SESSION['userName']))
?>
// Connect database.
//connect
$con = mysql_connect("****","*****","******");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
//datebase
mysql_select_db("*****", $con);
//select
$user_id = $_GET['user_id'];
$result = mysql_query("SELECT userinfo.user_id, userlogin.user_id
FROM userinfo
INNER JOIN userlogin
ON userinfo.user_id=userlogin=user_id");
while($row = mysql_fetch_array($result))
{
echo $row['name'] . '
' ;
echo $row['address'] . '
';
}
?>
Sorry if this seems confusing, as unfortunately my php skills aren't brilliant, but basically i'm just looking for help creating a log in feature, which then links the user the their profile, with their data present. Thanks in advance!