Jump to content

davetaylor91

New Members
  • Posts

    4
  • Joined

  • Last visited

davetaylor91's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I've change that part of the sql, however I still have the same problem, in that all results are being displayed, instead of results which share the same value from my tables. The reason I'm using 2 tables is because they serve different functions, one being a table containing log in data, one containing customer information, and it would be impractical to use only one table. Here is my updated 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"); // Create session username. header("location:home.php"); // Re-direct to home.php exit; }else{ // If not match. $message="--- Incorrect Username or Password ---"; } } // End Login authorize check. ?> <?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.name as name, userinfo.address as address, userlogin.username as username FROM userinfo INNER JOIN userlogin ON userlogin.user_id = userinfo.user_id"); while($row = mysql_fetch_array($result)) { echo $row['name'] . '</br> '; echo $row['username'] . '</br> '; echo $row['address'] . '</br> '; } ?>
  2. Oh I admit I didn't mean to have them as different names, I'm just saying I've changed this value but the problem still persists. So you don't think it's the sessions either?
  3. No, I don't think that's it. What I think it is, is that when entering data into my log in field, and then logging in its not directing me to a unique page, example (home.php?user_id=blahblah) but I don't know how to change this, and i'm a complete novice at sessions. But i'm not sure anymore.
  4. 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!
×
×
  • 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.