<?php
function preparedData(array $data): array
{
foreach($data as $key => $value) {
$data[$key] = trim($value);
$data[$key] = strip_tags($value);
$data[$key] = htmlspecialchars($value, ENT_QUOTES);
$data[$key] = stripslashes($value);
}
return $data;
}
function addTask(array $data)
{
$data = preparedData($data);
$db = new PDO("mysql:dbname=test; host=localhost", "root", "root");
$sql = "INSERT INTO tasks (name, task) VALUES (?, ?)";
$statement = $db->prepare($sql);
$statement->execute($data);
}
addTask($_POST);