[Solved] Serialize

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
User avatar
raymedia
Forum Commoner
Posts: 27
Joined: Thu Oct 09, 2003 6:36 am
Location: Melbourne, Australia

[Solved] Serialize

Post by raymedia »

Hi guys..im writing a page for a computer shop (my internship program).
they want to use database (mysql) and php to store the products details.

well..one of the my function uses "serialize". taking values from a form and store it in db.

Code: Select all

for ($i = 1; $i <=10; $i++)&#123;
	$componentName&#1111;] = $_POST&#1111;'componentName'.$i];
	$componentValue&#1111;] = $_POST&#1111;'componentValue'.$i];
&#125;

$componentName=serialize($componentName);
$componentValue=serialize($componentValue);
and at first things worked well when i unserialize it and use the array until.........when i enter ie. 17" monitor .. it stop working.. i think its the " or ' character corrupt the array ?? i think ;-)

so..is there any way around this? i tried to use preg_replace to replace the character to something else...

Code: Select all

function convertStringToSQLFormat($string) &#123;
	return preg_replace('"', '^', $string);
&#125;
but it gives me "Warning: No ending delimiter '"' found in /home/..........."

any help or advise is greatly appreciated
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Try...
$componentName=serialize(addslashes($componentName));
$componentValue=serialize(addslashes($componentValue));

you'll then need to use stripslahes() before unserializing it.
(could also use mysql_escape_string)
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

User avatar
raymedia
Forum Commoner
Posts: 27
Joined: Thu Oct 09, 2003 6:36 am
Location: Melbourne, Australia

Post by raymedia »

Thanks Mark...i have solved it. i use addslashes and McGruff..that was very good references..Thanks again
Post Reply