small serializing/unserializing problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ridwan
Forum Commoner
Posts: 55
Joined: Thu Aug 22, 2002 3:15 am

small serializing/unserializing problem

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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";
ridwan
Forum Commoner
Posts: 55
Joined: Thu Aug 22, 2002 3:15 am

OK gr8

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Missing a $ on value:

Code: Select all

foreach($test as $key=>$value)
Mac
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

:oops:

note to self: tripple check your writings. You're posting waste today...
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

volka wrote::oops:

note to self: tripple check your writings. You're posting waste today...
TGIF...
ridwan
Forum Commoner
Posts: 55
Joined: Thu Aug 22, 2002 3:15 am

sorry all

Post by ridwan »

sorry all seems as though friday caught up on me :cry: but thanx 4 all the assistance :wink:
Post Reply