cant set session vars

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
php3ch0
Forum Contributor
Posts: 212
Joined: Sun Nov 13, 2005 7:35 am
Location: Folkestone, Kent, UK

cant set session vars

Post by php3ch0 »

Can anyone tell me why this session variable will not be set?

I have checked that the session is started session_start()
Register Globals is on

Other session variables are displayed when I echo them so they are working fine.

$results_id is not empty.

Please help

Code: Select all

//registering the session var $result_id
mysql_select_db($database_db_connect, $db_connect);
$query_results = "SELECT id FROM quiz_scores ORDER BY id DESC";
$results = mysql_query($query_results, $db_connect) or die(mysql_error());
$row_results = mysql_fetch_assoc($results);
$totalRows_results = mysql_num_rows($results);
									
									
$results_id = $row_results['id'];
session_register("results_id");
code on the next page


Code: Select all

$score_id = $_SESSION['results_id'];
	echo $score_id;
again session started and register globals on
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

ok session started on first and second page got it :)

Code: Select all

$results_id = $row_results['id'];
session_register("results_id");
WRONG! don't use session register!

Code: Select all

$results_id = $row_results['id'];
$_SESSION['results_id'] = $row_results['id'];
try that. i cant dig up the article in the php.net site but its there and it goes over why not to use session_register() anymore
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

http://us3.php.net/manual/en/function.s ... gister.php

Has the details of why not to use it :)
User avatar
php3ch0
Forum Contributor
Posts: 212
Joined: Sun Nov 13, 2005 7:35 am
Location: Folkestone, Kent, UK

Post by php3ch0 »

thanks people. I'll give that a try.
Post Reply