$_SESSION setting problem

$_SESSION varibable does seem to want to set

Page 1 of 1

7 Replies - 1063 Views - Last Post: 21 March 2010 - 09:50 AM Rate Topic: -----

#1 Guest_Syrillia*


Reputation:

$_SESSION setting problem

Posted 18 March 2010 - 02:06 PM

I'm using the following code to set session variables but it's not working for some reason.

		$result = mysql_query("SELECT * FROM bands WHERE email = '" . $_POST['signin_email'] . "'");
		$row = mysql_fetch_array($result);

		if ($row['password'] == $password) {
			$result2 = mysql_query("SELECT * FROM bands WHERE email = '" . $row['id'] . "'");
			$_SESSION = mysql_fetch_array($result2);
			echo "You've successfully logged in!<br><br>";
			echo "<a class='companyheader' href='?page=dashboard'>Dashboard</a> | <a class='companyheader' href='?page=home'>Home</a>";
			if (isset($_SESSION['email'])) {
				echo "You're working!";
			}
		} else {
			echo "Oops!";
		}



I'm getting the "You've successfully logged in!" message, but not the "You're working!" message and I don't know why. Any assistance would be brilliant.

Sam

Is This A Good Question/Topic? 0

Replies To: $_SESSION setting problem

#2 Aurel300  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 230
  • Joined: 10-November 07

Re: $_SESSION setting problem

Posted 18 March 2010 - 03:23 PM

Hm...
First of all, did you session_start();?
And, if so... I am not really sure about the "$_SESSION = something" line... Try "$_SESSION['mysql_data'] = ...".
Was This Post Helpful? 0
  • +
  • -

#3 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 542
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: $_SESSION setting problem

Posted 18 March 2010 - 08:45 PM

View PostAurel300, on 18 March 2010 - 05:23 PM, said:

And, if so... I am not really sure about the "$_SESSION = something" line... Try "$_SESSION['mysql_data'] = ...".


There shouldn't be any problem with that. When testing a script I have sometimes set data in $_POST manually to be able to test already typed code. Granted it's not really a great idea to do it that way, but if the session is started properly, it should still work.
Was This Post Helpful? 0
  • +
  • -

#4 Xuhybrid  Icon User is offline

  • D.I.C Head

Reputation: 30
  • View blog
  • Posts: 106
  • Joined: 20-January 10

Re: $_SESSION setting problem

Posted 19 March 2010 - 04:58 AM

Perhaps overwriting the entire variable is blocked in php.ini settings, or is not supported in older PHP versions. In any case, it might be a good idea to loop through the data.

Oh actually i just noticed you are using mysql_fetch_array.
To get the key name as email is needs to be mysql_fetch_assoc.

This post has been edited by Xuhybrid: 19 March 2010 - 04:58 AM

Was This Post Helpful? 0
  • +
  • -

#5 Ridikule  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 68
  • Joined: 29-September 05

Re: $_SESSION setting problem

Posted 19 March 2010 - 09:26 AM

View PostXuhybrid, on 19 March 2010 - 03:58 AM, said:

Oh actually i just noticed you are using mysql_fetch_array.
To get the key name as email is needs to be mysql_fetch_assoc.


mysql_fetch_array should work. In this array, both the numeric and the associative keys are defined.
mysql_fetch_assoc - associative keys only.
mysql_fetch_row - numeric keys only.
Was This Post Helpful? 0
  • +
  • -

#6 Guest_Syrillia*


Reputation:

Re: $_SESSION setting problem

Posted 19 March 2010 - 10:44 AM

Thank everyone for the help, but the problem remains. The first two lines in my index.php file are:

<?php
	session_start();



I'm pretty sure that's fine. Also, it's not to do with standard server procedure, because I have other sites that are running fine.

I can log into one site ('/site1') and then go to '/site2' and it will still be logged because both sites are using sub-directories. Could that be part of the problem?

Many thanks,

Sam
Was This Post Helpful? 0

#7 Aurel300  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 230
  • Joined: 10-November 07

Re: $_SESSION setting problem

Posted 19 March 2010 - 11:44 AM

Well, step debug!
Put an echo $someVariable; wherever there is a new variable, or its value was changed. Check if the output what you wanted. If not, you pin-pointed the problem, if yes, proceed.
Was This Post Helpful? 0
  • +
  • -

#8 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1002
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: $_SESSION setting problem

Posted 21 March 2010 - 09:50 AM

As above, just debug.

Add an else clause (to the if($_SESSION .. )) that simply does a print_r($_SESSION);, see what's going on in there.

If it's blank, the session probably isn't being started correctly (is error reporting on?).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1