Hello everybody,
I want to insert some data with an array to my mysql database, but it won't work. These are my codes, what could be the problem?
register.php:
if (empty($_POST) === false) {
$required_fields = array('first_name','last_name','number','district','street', 'house_number', 'appointment_date', 'comment', 'anchor');
foreach($_POST as $key=>$value)
{
if (empty($value) && in_array($key, $required_fields) === true)
{
$errors[] = 'Fields marked with an asterisk are required';
break 1;
}
}
}
?>
<h1>Register</h1>
<?php
if (isset($_GET['success']) && empty($_GET['success'])) {
} else {
if (empty($_POST) === false && empty($errors) === true) {
$register_data = array(
'first_name' => $_POST['first_name'],
'last_name' => $_POST['last_name'],
'number' => $_POST['number'],
'district' => $_POST['district'],
'street' => $_POST['street'],
'house_number' => $_POST['house_number'],
'appointment_date' => $_POST['appointment_date'],
'comment' => $_POST['comment'],
'achor' => $_POST['anchor']
);
echo $register_data;
register_user($register_data);
header('Location: register.php?success');
exit();
} else if (empty($errors) === false) {
echo output_errors($errors);
}
register_user function php file:
function register_user($register_data) {
array_walk($register_data, 'array_sanitize');
$fields = '`' . implode('`, `', array_keys($register_data)) . '`';
$data = '\'' . implode('\', \'', $register_data) . '\'';
mysql_query("INSERT INTO `sikeres` ($fields) VALUES ($data)");
}
If someone could help me i would really appreciate it!
Tibor