$fields = array_keys($_POST);
if (!empty($fields)) {
$names = implode('`, `', $fields);
$values = implode(', :', $fields);
$sql = "INSERT INTO customers ( `".$names."` ) VALUES ( :".$values." )";
print_r($sql);
$addRandom = $pdo->prepare($sql);
foreach ($fields as $field) {
$addRandom->bindValue(":{$field}", $_POST[$field]);
}
$boolean = $addRandom->execute();
if ($boolean){
echo 'INSERTED';
} else {
echo 'FAILED';
}
}
0
solved php pdo $_post insert