looking for help getting data from my tables.
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.
Here is my loginpage code
<?php
// 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.
?>
Here is the code for my homepage, which is were the information will be shown to the user, upon login.
<?php
session_start();
if(isset($_SESSION['userName']))
?>
<?php
// 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'] . '</br>' ;
echo $row['address'] . '</br>';
}
?>
So far all i'm doing is displaying all the information from my userinfo table, and what I want is to limit this content to showing information that matches the user_id from the userlogin table to the user_id of the userinfo table and display the results.
[EDIT] I've edited my mysql in my homepage code, and now i'm displaying no results, and i'm still unsure how to make this work.
Thanks for the help in advance!