Passing an Array to mysql
Posted: Thu Jan 29, 2004 9:38 pm
Ok, I have a few check boxes. I want them to be stored in a table, and I am using the following code to do it. The only problem is - all the table ever stores is "Array". If you can tell me how to store it as ANYTHING other than "Array", that would just make my day!
Thanks in advance for any help!! This thing is gonna put me in an ol' folks home before too much longer.
Code: Select all
<?php
// -- setup of the custom values --
$site_extras = array (
array (
"ServerName", // unique name of this extra field (used in db)
"Server Name", // how this field will be described to users
$EXTRA_SELECTLIST, // type of field
// List of options (first will be default)
//array ( "test1", "test2" ), (Unused)
0 // arg 2 (unused)
)
);
// --- snippet: Input checkboxes ---
if ( $extra_type == $EXTRA_SELECTLIST ) {
// show custom select list.
echo "<input type="checkbox" name="" . $extra_name . "[]" value="test1">Test 1";
echo "<input type="checkbox" name="" . $extra_name . "[]" value="test2">Test 2";
//--- mySQL handling ---
for ( $i = 0; $i < count ( $site_extras ) && empty ( $error ); $i++ )
{
$sql = "";
$extra_name = $site_extras[$i][0];
$extra_type = $site_extras[$i][2];
$extra_arg1 = $site_extras[$i][3];
$extra_arg2 = $site_extras[$i][4];
$value = $$extra_name;
if ( strlen ( $$extra_name ) || $extra_type == $EXTRA_DATE )
{
if ( $extra_type == $EXTRA_SELECTLIST )
{
$sql = "INSERT INTO webcal_site_extras " .
"( cal_id, cal_name, cal_type, cal_data ) VALUES ( " .
"$id, '$extra_name', $extra_type, '$value' )";
}
}
}
?>