as always, I have tried to research and solve the problem based on already existing questions but can't wrap my head around it. I am probably doing many things wrong. In the html form, I have input types text,number, title, as well as textarea, so maybe that might account for things not working too?
Here's a link to the thing I'm trying to build: http://postimg.org/image/9mgm6l9hj/
Here's my INSERT query function
function register_hangout($register_hangout_data) {
array_walk($register_hangout_data, 'array_sanitize');
$hangout_fields = '`' . implode('`, `', array_keys($register_hangout_data)) . '`';
$hangout_data = '\'' . implode('\', \'', $register_hangout_data) . '\'';
mysql_query("INSERT INTO hangouts ($hangout_fields) VALUES ($hangout_data)");
}
And here's the code, which, as of now, it does redirect me to hangout.php?success, but doesn't echo "Successssss" or insert into the DB:
if (empty($_POST) === false) {
$required_fields = array('title','dd' ,'mm','yyyy', 'hour', 'minutes', 'location', 'aim', 'description');
foreach($_POST AS $key=>$value) {
if (empty($value) && in_array($key, $required_fields) === true) {
$errors[] = 'Fields marked with an asterisk are required.';
break 1;
}
}
print_r($errors);
}
?>
<?php
if (isset($_GET['success']) && empty($_GET['success'])) {
echo 'Successssssss.';
} else {
// there's one curly brace after the html form tied to this else right above
if (empty($_POST) === false && empty($errors) === true) {
//insert hangout data in mysql database
$register_hangout_data = array(
'title' => $_POST['title'],
'dd' => $_POST['dd'],
'mm' => $_POST['mm'],
'yyyy' => $_POST['yyyy'],
'hour' => $_POST['hour'],
'minutes' => $_POST['minutes'],
'location' => $_POST['location'],
'aim' => $_POST['aim'],
'description' => $_POST['description']
);
register_hangout($register_hangout_data);
header('Location: hangout.php?success');
// exit
}
elseif (empty($errors) === false) {
//output errors
echo output_errors($errors);
}
I can't get my head around why these aren't even inserted into the DB, let alone using proper integer functions, sanitization, proper date time functions and format, so please help me solve my actual problem before diving into what other things I should do to this code.