I'm trying to insert the datas with php & pdo. I'm writing this below codes for insert function and I call them like this php_insert_data("admin", array( 'user_name', 'user_pwd', 'user_email', 'profile_created_on' ), array( 'Administrator', '123456', 'admin@gmail.com', 'date here' ));
. I tried this below code. But it doesn't insert the datas into db table. How do I pass these above column names and column values properly?
function php_insert_data($table_name, array $field_name, array $field_values)
{
global $dbh;
foreach($field_name as $f_names)
{
$transform_array_fnames[] = $f_names;
}
foreach($field_values as $f_values)
{
$transform_array_fvalues[] = $f_values;
}
$comma_fnames = implode(',', $transform_array_fnames);
$comma_fvalues = implode(',', $transform_array_fvalues);
$insert_query = $dbh->prepare("INSERT INTO $table_name SET $comma_fnames = $comma_fvalues");
$insert_query->bindValue(':comma_fvalues', $comma_fvalues);
$insert_query->execute();
}