Page 1 of 1

cant set session vars

Posted: Wed Nov 30, 2005 10:02 am
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

Posted: Wed Nov 30, 2005 10:14 am
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

Posted: Wed Nov 30, 2005 10:29 am
by Jenk
http://us3.php.net/manual/en/function.s ... gister.php

Has the details of why not to use it :)

Posted: Thu Dec 01, 2005 2:39 am
by php3ch0
thanks people. I'll give that a try.