SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: Help with SESSIONS
-
Jul 5, 2008, 08:11 #1
- Join Date
- Mar 2008
- Posts
- 151
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Help with SESSIONS
I have the following code where i've already initialized the $_SESSION['member_ID] variable, but i want i want to know is how can i use that variable outside of the below php code... so i can query the database using the $_SESSION['member_ID'] further down in the html code... (see inside wrapper tag)
<?php
session_start();
if(!session_is_registered('member_ID')) :
header('Location: index.php?msg=requires_login');
endif;
include 'db.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="wrapper">
<?php
// HERE IS WHERE I WANT TO USE $_SESSION['member_ID']
$_SESSION['member_ID'];
?>
-
Jul 5, 2008, 08:38 #2
- Join Date
- Dec 2007
- Posts
- 358
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Session variables are similar to regular variables. For example, you can use this code:
Code:$memberId = $_SESSION['member_ID'];
Then you can use this variable to create a database query.
These sections of the PHP manual may be useful:
http://php.net/manual/en/book.mysql.php
http://php.net/manual/en/book.mysqli.php
-
Jul 5, 2008, 09:02 #3PHP Code:
session_start();
$query = "SELECT login FROM users WHERE id = '%d' ";
$sql = mysql_query( sprintf( $query, $_SESSION['member_ID']) ) or die( mysql_error() );
$row = mysql_fetch_array( $sql );
echo $row['login'];
my mobile portal
ghiris.ro
Bookmarks