Array Function issue
Posted: Fri Jul 22, 2011 5:13 am
I'm looking for a better way to convert my array into a MySQL string.
My array will be
and here is my function
My array will be
Code: Select all
$my_array = name => full_name,
email => email@email.com,
birthdate => my/bi/thday
Code: Select all
function db_input($user_details) {
$string_quer = 'INSERT INTO emails (';
foreach($user_details as $user_key => $user_val) {
$string_quer .= ''. $user_key .', ';
}
substr($string_quer, 0, -2); //remove extra ', '
$string_quer .= ') VALUES (';
foreach($user_details as $user_key => $user_val) {
$string_quer .= ''. $user_val .', ';
}
substr($string_quer, 0, -2); //remove extra ', '
$string_quer .= ')';
$mysql_result = mysql_query($string_quer);
if ($mysql_result) {
return TRUE;
} else {
return FALSE;
}
}