Jump to content

Recommended Posts

Hi everyone,

 

I need to display records in a database that are only specific to the user ID that is logged in. Do i need to pass through variables in a session?  Currently i have -

 

code:

 

<?php

session_start();

 

require "connect.php";

if (isset($_SESSION['Login']) == false){

header("Location: Login.php");

exit();

}

//$query = "select * from proposals";

 

$query = "SELECT * FROM proposals ORDER BY proposalID DESC";

$result = mysql_query($query, $connection)

or die ("mySQL Error: ".mysql_error());

?>

 

Thanks guys.

 

David

I have put -

 

<?php

session_start();

$SESSION['Name'] = $Name;

 

require "connect.php";

 

on my login pages and -

 

<?php

session_start();

$SESSION['Name'];

 

require "connect.php";

 

Where i want to call it into, at current its not working, can anyone help where i am going wrong?

 

Thanks Lads

 

my login page -

 

<?php

session_start();

$_SESSION['Name'] = $Name;

?>

<script language="JavaScript" type="text/JavaScript">

form action="logincheck2.php" method="get">

  <p align="center"> </p>

  <p align="center"> </p>

<p align="center"><span class="style1">User Name_</span><br>

  <input name="Login" type="text">

 

my login check -

 

<?php

session_start();

$_SESSION['Name'] = $Name;

 

require "connect.php";

$Login = $_GET['Login'];

$Password = $_GET['Password'];

$query = "select * from client where Login = '".$Login."' AND Password = '".$Password."'";

 

$result = mysql_query($query, $connection) or die ("unable to perform query<br>$query");

 

$row= mysql_fetch_array($result);

if ($row != null)

{

$_SESSION['Login'] = $row['Password'];

$_SESSION['Name'] = $row['Name'];

 

header("Location: welcompage2.php");

exit();

}

else

{

header("Location: login2.php");

exit();

}

?>

 

Sorry for a lot of code lads, just thought it may give a better indication than what I can explain.

 

Thanks again

 

 

Ok, your login name is already being set here

 

$_SESSION['Login'] = $row['Password'];

$_SESSION['Name'] = $row['Name'];

 

So if you want to add the ID, just add another session for the ID field.

 

So remove all the other $_SESSION['Name'] = $Name; code because they are just overwriting your existing session you already set.

 

Now, what do you want to do with the ID?

ok cool, thats created, now i want the records only with the 'Name' field that correlates to them when they login to be displayed. eg - If the login is 'Alex' i want only the records in the DB which under the field 'Name' display 'Alex' to be shown, and all the others by other users to be hidden.

 

Thanks lads

You are already getting that info when they log in

 

$query = "select * from client where Login = '".$Login."' AND Password = '".$Password."'";

 

  $result = mysql_query($query, $connection) or die ("unable to perform query

$query");

 

  $row= mysql_fetch_array($result);

 

So you can either set a session for each item, or you can do the query again on the page you want to display it, but you won't have to re-verify the PW since you already verified it.

ok but that reads the 'login' and not the 'Name' field, here is a pic of my Db-

 

http://i32.photobucket.com/albums/d36/B_318is/db.jpg

 

Do i now have to ecco the session within the page i want it to display within?

 

Cheers lads

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.