I have php page that you can type in a number and then click the submit button and it should insert the column in the table. The problem I have is that it isn't inserting the value but just leaving an empty field.
Function 1 post values clean
function post($name)
{
if (isset($_POST[$name]))
{
if (is_array($_POST[$name]))
{
return array_map(function($item){
return htmlspecialchars(trim($item));
}, $_POST[$name]);
}
return htmlspecialchars(trim($_POST[$name]));
}
}
Function 02
function post_form(...$except_these)
{
unset($_POST['submit']);
$post_form = [];
$error = false;
foreach($_POST as $key => $value){
if ( !in_array($key, $except_these) && !post($key) )
{
$error = true;
} else {
$post_form[$key] = post($key);
}
}
if ( $error )
{
return false;
}
return $post_form;
}
post
$_POST['submit'] = 1;
$_POST['user_name'] = 'Arman';
$_POST['user_email'] = 'abc';
$_POST['user_password'] = '1234';
insert
$post_form = post_form('submit');
$query = $db->prepare("INSERT INTO users SET
user_name = ?,
user_email = ?,
user_password = ?
");
$insert = $query->execute($post_form);
no error message but mysql columns is empty.