I have a page that is basically created using a JSON file. This is processed to create a form that is then posted. The following code is designed to capture the input and write to the database.
<?php
//need to make the connection
include '../authenticate/config.php';
$pdo = new PDO($dsn, $DATABASE_USER,$DATABASE_PASS, $options);
$data=array();
foreach ($_POST as $key => $value) {
$data[':'.$key]=$value;
}
$sql="INSERT INTO ITcomp ( " . implode(', ',array_keys($_POST)) . ") VALUES (" . implode(', ',array_values($data)) . ")";
$stmt = $pdo->prepare($sql);
$res = $stmt->execute($data);
?>
The issue is that one or more of the 10 inputs in this case contains a text field, so when it tries to write it to the table I get an error. For instance if the input text is THIS then it will say that THIS is an unknown column. How can I solve this? TIA