Jump to content

[SOLVED] passing through variables in a session??


rnb_cassanova

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.