Page 1 of 1

small serializing/unserializing problem

Posted: Fri May 16, 2003 8:12 am
by ridwan
I seem o not be able to get this right:

I serializing and sending data to a field in my table using serialze, it serializes and inserts the info correctly but when I call my info though it just displays 'array'

Does anyone know what my problem is, I have heard some talk about slashing data, could that be the problem or could it be something i'm unaware of :?

I am including the code so that everyone understands what I am getting at:

Code: Select all

<?php
 include ("../scripts/conf.php");

$test = array (1=>'one',2=>'two',3=>'three',4=>'four',5=>'five',6=>'six');
$serial_test = serialize($test);

          $query = "UPDATE sitecontent SET image = '$serial_test' WHERE Section = 'welcome' ";
          $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
          //$row = mysql_fetch_object($result);
//record into database

//once the data is retrieved, use unserailize
$test = unserialize($serial_test);
echo $test;
?>
Thanks all

Posted: Fri May 16, 2003 8:24 am
by volka
you can't simply echo an array. oh, of course you can but you'll get Array as output ;)
you might print each (string) entry

Code: Select all

test = unserialize($serial_test);
foreach($test as $key=>value)
    echo $key, '=>', value, "\n";

OK gr8

Posted: Fri May 16, 2003 8:56 am
by ridwan
That answers that question but why now when i try your "for each" statement i get a parse error saying that it is expecting a variable or '$' on my foreach line ?? :?

Is there something i am forgetting to do, btw I just changed this ->

Code: Select all

test = unserialize($serial_test);
to this:

Code: Select all

$test = unserialize($serial_test);
and did check my PHP manual and all seems in order.

Posted: Fri May 16, 2003 9:02 am
by twigletmac
Missing a $ on value:

Code: Select all

foreach($test as $key=>$value)
Mac

Posted: Fri May 16, 2003 9:09 am
by volka
:oops:

note to self: tripple check your writings. You're posting waste today...

Posted: Fri May 16, 2003 9:42 am
by twigletmac
volka wrote::oops:

note to self: tripple check your writings. You're posting waste today...
TGIF...

sorry all

Posted: Mon May 19, 2003 2:14 am
by ridwan
sorry all seems as though friday caught up on me :cry: but thanx 4 all the assistance :wink: