Page 1 of 1

[Solved] Serialize

Posted: Tue Mar 23, 2004 7:08 pm
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

Posted: Tue Mar 23, 2004 7:29 pm
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)

Posted: Tue Mar 23, 2004 9:21 pm
by McGruff

Posted: Tue Mar 23, 2004 10:25 pm
by raymedia
Thanks Mark...i have solved it. i use addslashes and McGruff..that was very good references..Thanks again