Lost Password?


Go Back   CodeCall Programming Forum > Web Development Forum > PHP Forum

PHP Forum Use this forum to discuss all aspects of PHP Development. PHP is a server-side, cross-platform, HTML embedded scripting language that lets you create dynamic web pages.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-14-2008, 05:38 PM
gszauer's Avatar   
gszauer gszauer is offline
Programmer
 
Join Date: Nov 2007
Location: Florida
Age: 19
Posts: 113
Rep Power: 4
gszauer is on a distinguished road
Default Problems passing a serialized array in a session variable

Hi all, i have a multidimentional array i want to pass as a session variable.
Of course i serialized the array.
I have 2 files, set.php & get.php
set.php populates the array, and get.php prints it out. below is my code:

Set.php:
PHP Code:
<?php
session_start
();
$array $_SESSION['array'];

if (
$array) {
    
$associative unserialize($array);
    print 
"Array Exists <br />";
} else {
    
$associative = array();
    print 
"Array Created <br />";
}

$associative[0] = array();
$associative[1] = array();
$associative[2] = array();
$associative[0][0] = "0-0";
$associative[0][1] = "0-1";
$associative[1][0] = "1-0";
$associative[1][1] = "1-1";
$associative[2][0] = "2-0";
$associative[2][1] = "2-1";


$_SESSION['array'] = serialize($array)
?>
Get.php:
PHP Code:
<?php
session_start
();
$array $_SESSION['array'];

if (
$array) {
    
$associative unserialize($array);
    print 
"Array Exists <br />";
} else {
    
$associative = array();
    print 
"Array Created <br />";
}

for (
$i 0$i count ($associative); $i++){
    print 
"Associative array: ".$associative[$i];
    print 
"Subarray1: ".$associative[$i][0];
    print 
"Subarray2: ".$associative[$i][1];
}

?>
So i navigate to set.php, then to get.php but nothing prints....
What am i doint wrong?
__________________
Quote:
Originally Posted by ~Aristotle
It is the mark of an educated mind to entertain a tought without accepting it
If my post was helpful, please help me build some rep
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 02-15-2008, 09:59 AM
Jordan's Avatar   
Jordan Jordan is offline
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Posts: 9,203
Last Blog:
Ext JS or Ext GWT
Rep Power: 20
Jordan is just really niceJordan is just really niceJordan is just really niceJordan is just really nice
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan
Default

Do you have display_errors on? It would seem to me that you have a fatal error somewhere and are not receiving the error message because this is turned off.

Check this tutorial:
Debugging with PHP
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog
The CodeCall Wiki is now fully integrated with vBulletin users! Check it out and add some new pages!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-15-2008, 11:04 AM
Jaan's Avatar   
Jaan Jaan is offline
Mod
 
Join Date: Dec 2006
Location: Estonia
Age: 17
Posts: 930
Last Blog:
AdStar Ad Control Pa...
Rep Power: 16
Jaan is a jewel in the roughJaan is a jewel in the roughJaan is a jewel in the roughJaan is a jewel in the rough
Send a message via MSN to Jaan
Default

This is good also Jordan but it would be easier to just use

PHP Code:
ini_set("display_errors"true); 
or
PHP Code:
ini_set("display_errors""1"); 
and if you want to turn errors off you can delete that line or change true to false and 1 to 0
__________________


Cheap & Professional Web Design | Need help? Send a PM
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-15-2008, 12:18 PM
gszauer's Avatar   
gszauer gszauer is offline
Programmer
 
Join Date: Nov 2007
Location: Florida
Age: 19
Posts: 113
Rep Power: 4
gszauer is on a distinguished road
Default

Nope, not the problem.
I re-vamped the code, now when i refresh the page it should show me a new entery...
PHP Code:
<?php
ini_set
("display_errors"true); 
session_start();
// id, and color_selection are passed via the $_GET method

print "--- Debug info ---<br />";
print 
"Passed color: ".$_GET['color_selection']."<br />";
if (
$_SESSION['color']) {$color unserialize($_SESSION['color']); print "Color array loaded <br />";} else {$color = array(); print "Color array created <br />";}

for (
$i 0$i count ($color); $i++) {
     print 
"<br />--- Reading Array <br /> Index: ".$i."<br />ID: ".$color[$i]["id"]."<br />Value: ".$color [$i]["value"]."<br />";
}

$arraySize count ($color);
$color[$arraySize] = array();
$color[$arraySize]["id"] = $_GET['id'];
$color[$arraySize]["value"] = $_GET['color_selection'];
print 
"<br />--- Writing to Array --- <br />Index: ".$arraySize."<br />ID: ".$color[$arraySize]["id"]."<br />Value: ".$color [$arraySize]["value"]."<br />";

$_SESSION['color'] = $color;

?>
Its live at: http://szauer.net/scripts/functionte...selection=this
__________________
Quote:
Originally Posted by ~Aristotle
It is the mark of an educated mind to entertain a tought without accepting it
If my post was helpful, please help me build some rep
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Python 2D array question annannienann Python 3 04-23-2007 05:36 PM


All times are GMT -5. The time now is 07:22 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 97%

Ads