It looks correct to set the session variable on page load assuming that it occurs after the recordset code.
If you page has a form on it that submits to itself,. the form could be resetting the session variable when it submits. If the Recordset is filtered, the form may not pass the variabel the recordset needs. In this case, the session variable will be set properly when the page loads, but reset to blank when the form submits.
Hi, Jason
Here is the code:
<?php require_once('Connections/db_conn.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$colname_Var_RS = "-1";
if (isset($_SESSION['kt_login_id'])) {
$colname_Var_RS = (get_magic_quotes_gpc()) ? $_SESSION['kt_login_id'] : addslashes($_SESSION['kt_login_id']);
}
mysql_select_db($database_db_conn, $db_conn);
$query_Var_RS = sprintf("SELECT * FROM login_tb WHERE ID = %s", GetSQLValueString($colname_Var_RS, "int"));
$Var_RS = mysql_query($query_Var_RS, $db_conn) or die(mysql_error());
$row_Var_RS = mysql_fetch_assoc($Var_RS);
$totalRows_Var_RS = mysql_num_rows($Var_RS);
?>
<?php
if (!session_id()) session_start();
$_SESSION['User_Email_SV'] = $row_Var_RS['Email']; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="verify-v1" content="c1YO7f6F7gbqyIflhw3/mbQL2K4ImChdWo5K/SwHxJA=" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<p>Index.php</p>
<p> <?php echo $_SESSION['User_Email_SV']; ?>
</p>
</body>
</html>
<?php
?>
Thanks