Jump to content


Photo

Unserialize returning false?


  • Please log in to reply
2 replies to this topic

#1 nuglobe

nuglobe
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 17 October 2006 - 03:35 AM

Alright so this is the entry that was stored in the database:

a:1:{s:6:"Andrew";s:17:"me@gmail.com";}

Here is the function that serializes it. Note - $_SESSION['stateEmails'] is passed through as the request array.

function submit_request($uID, $requestArray){

	$players = serialize($requestArray);
	$status = 1;

	
	$query = "INSERT INTO requests (uID, playersID, status) VALUES ('$uID', '$players', '$status')";
	mysql_query ($query) or die ('Could not submit request!.');
		 
}


Here is the code that creates the array.

$_SESSION['stateEmails'][$rowprof['uFName']] = $rowprof['uEmail'];

Its in a loop, so there cool be more to it then the one posted at the top.

And finally here is the function I am trying to use to pull from the database, unserialize and display.

function get_open_requests($uID)
{

	$status = 1;
	
	$query = "SELECT playersID FROM requests WHERE uID = $uID AND status = $status";
	$pull = mysql_query($query);
	
	$players = unserialize($pull);
	
	print_r($players);

}

What am I doing wrong?

#2 manichean

manichean
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 17 October 2006 - 05:52 AM

Hello the problem lies in this section of your code

Your code:

function get_open_requests($uID)
{

$status = 1;

$query = "SELECT playersID FROM requests WHERE uID = $uID AND status = $status";
$pull = mysql_query($query);

$players = unserialize($pull);

print_r($players);

}


Completed fixed code:

function get_open_requests($uID)
{
$status = 1;
$query = "SELECT playersID FROM requests WHERE uID = '$uID' AND status = '$status'";
$pull = mysql_query($query);
$row = mysql_fetch_assoc($pull);
$players = unserialize($row['playersID']);
print_r($players);
}


always remember a mysql_query stored into a variable storeds its RESOURCE ID # not the values obtained from the table. And always encapsulate your variables in a select or insert statment with ' ' single quotes

Hope this helps ya
cheers

#3 nuglobe

nuglobe
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 17 October 2006 - 04:57 PM

Thanks!  :D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users