Page 1 of 1

Pullling data from mysql to put into session.

Posted: Thu Jun 19, 2008 10:24 pm
by phillyrob
I am trying to pull information from mysql db to put into a session and can't seem to get it to work. After a user logs in, I want to greet them by user name ( got that part0 but I also want to pull the school form the database that they entered when they registered. I get nothing on the landing page ( other the than the user name). Here is my code. Can someone spot what is wrong? everything works except for the porting that pulls from the db. The fist section is from the login page.

Login
**************************

<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['username'])) {
$loginUsername=$_POST['username'];
$password=md5($_POST['password']);
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "option.php";
$MM_redirectLoginFailed = "message2.htm";
$MM_redirecttoReferrer = false;
mysql_select_db($database_modulatemedia, $modulatemedia);

$LoginRS__query=sprintf("SELECT username, password FROM users WHERE username=%s AND password=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));

$LoginRS = mysql_query($LoginRS__query, $modulatemedia) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);



$sql = "SELECT school FROM users WHERE username = '{$_POST['username']}'";

$rs = mysql_query($sql);

$row = mysql_fetch_array($rs);




if ($loginFoundUser) {
$loginStrGroup = "";

//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
$_SESSION['MM_school'] = $row['school'] ;





if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>

Landing page after login (the $_SESSION['MM_Username'].".". works fine) code below
********************************************************

<?php
if (!isset($_SESSION)) {
session_start();
}



echo "Welcome". " ". $_SESSION['MM_Username'].".". " "."You are currently log into your account.";
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";




//echo $row['school'];

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;

Re: Pullling data from mysql to put into session.

Posted: Thu Jun 19, 2008 11:10 pm
by WebbieDave
I fail to see where you are using $_SESSION['MM_school'] on the landing page. For info on using session variables, check out:
http://www.tizag.com/phpT/phpsessions.php

Or the other numerous tutorials on this subject found via google.

Re: Pullling data from mysql to put into session.

Posted: Thu Jun 19, 2008 11:17 pm
by phillyrob
No realize that it is not on the code here, but I have used that on the landing in multiple ways and nothing shows up at all. But thanks. I should have been a little more clear about that. Thanks Webbiedave.