[SOLVED] Re: can a session be used in a query?



changing the title; but nobody else does it which leads to some great out of context discussions :)

Terion Miller wrote:
SOLVED: Thanks everyone I got it working it was the loop...took it out and
now it works like a charm!! Is there a way to mark things solved?

On Wed, Jan 7, 2009 at 1:46 PM, Terion Miller <webdev.terion@xxxxxxxxx>wrote:

I am still struggling with getting my sessions and logins to pull just the
allotted data that each user is allowed...
I have the session working, and can echo it to see that .. what I'm having
problems with is this : I want to pull the data specific to each user
..right... so far I either get all data regardless of user privileges or I
get nothing.. a blank page, I have tried so many ways but never one that
works: here are a few I have worked with----

This one pulls all data regardless of user level:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
session_start();
include("inc/dbconn_open.php");


if (empty($_SESSION['AdminLogin']) OR $_SESSION['AdminLogin'] <> 'True' ){
header ("Location: LogOut.php");
}


$query = "SELECT * FROM admin WHERE AdminID = AdminID";
$result = mysql_query ($query);
$row = mysql_fetch_object ($result);
?>

From there I tried:

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
session_start();
include("inc/dbconn_open.php");


if (empty($_SESSION['AdminLogin']) || $_SESSION['AdminLogin'] != true){
header ("Location: LogOut.php");
}


$query =
"SELECT * FROM `admin` WHERE `UserName` = `{$_SESSION['user']}";
$result = mysql_query ($query);
$row = mysql_fetch_assoc($result);
?>

this one didn't work with the if $row -> statements that are used to select
what menu items to load.

Now I have this one which loads nothing, nil a blank page:

$query = "SELECT * FROM admin WHERE UserName = "$_SESSION['user']" ";
$result=mysql_query($query) or die('Queryproblem: ' . mysql_error() .
'<br />Executed query: ' . $query);
if (mysql_num_rows($result) >= '1'){
while ($row = mysql_fetch_assoc($result)){
echo $row['AddEditAdmin']; //to print out the value of column
'var1' for each record
}
}else{
echo 'No records found.';
}
?>

anyone have ideas for me, the session user is working, and I need to use it
in the query to pull only that users data I also on the login page where I
set that session all set it to = $UserName but when I try and use that in
the query UserName = $UserName I get an undefined variable error...

Really trying but not quite getting it...



.



Relevant Pages

  • Re: can a session be used in a query?
    ... I have the session working, and can echo it to see that .. ... in the query to pull only that users data I also on the login page where I ... the query UserName = $UserName I get an undefined variable error... ...
    (php.general)
  • Re: can a session be used in a query?
    ... I've noticed that I somtimes have to get the page to load ... I have the session working, and can echo it to see that .. ... in the query to pull only that users data I also on the login page where I ... the query UserName = $UserName I get an undefined variable error... ...
    (php.general)
  • Re: [PHP] can a session be used in a query?
    ... I have the session working, and can echo it to see that .. ... in the query to pull only that users data I also on the login page where I ... the query UserName = $UserName I get an undefined variable error... ...
    (php.general)
  • Re: os users, sessions, and connections.
    ... From what I've read a session is a logged connection. ... do the following (paddr is the address of the process ... select sid, serial#, paddr, username from v$session ...
    (comp.databases.oracle.server)
  • Re: Sessions and clients
    ... This entrance page gives out a random session URL. ... you get the login page. ... user gets a *different* username. ... closes the browser, or the browser, computer, or Internet connection ...
    (comp.lang.php)