Mission:
To create a function which will 'clean up' the contents of an array so
it is ready to be inserted in a MySQL table or to use as a source for
updating a row in a MySQL table.
Background:
I'm using the dbWrapper class at http://www.ricocheting.com/code/php/mysql-database-class-wrapper-v3
Since I pre-populate all my fields in a form with "" if I have no
other default value, before using his db->insert() or db->update(), I
need to convert all those fields which have a submitted value of "" to
NULL. Easy enough, foreach() through the array and if(trim($key) ==
"" or trim($key) == "Please select"), set the $val as "NULL".
Problem:
All the form data is in a $_SESSION['Something'] array. Rather than
passing all the array elements TO the function which will do this
cleanup, then pass all the values back and substitute the new values
in the original array, I'd much prefer to update the
$_SESSION['Something'] array from within the function, but I'm not
getting the syntax right for updating directly to the array.
Here's what I have (but doesn't work);
function dbPrep($Arr)
{
foreach($Arr as $key=>$val)
{
if (trim($val) == '' or trim($val) == 'Please select')
{
$Arr[$key] = 'NULL';
}
}
return TRUE;
}
Then down in the code, I'm calling it like this:
if (dbPrep($_SESSION['Something']))
{
$primary_id = $db->insert(TABLE, $_SESSION['Something']);
}
Any suggestions on how to get this to update the
$_SESSION['Something'] array would be much appreciated!
Jeff
--
This group is managed and maintained by the development staff at 360 PSG. An enterprise application development company utilizing open-source technologies for todays small-to-medium size businesses.
For information or project assistance please visit :
http://www.360psg.com
You received this message because you are subscribed to the Google Groups "Professional PHP Developers" group.
To post to this group, send email to Professi...@googlegroups.com
To unsubscribe from this group, send email to Professional-P...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/Professional-PHP