Answer the question
In order to leave comments, you need to log in
How to change the data from the form and return it back to the array?
There is a function that takes data from $_POST and puts it in the database
function addTask($addData){
$db = new PDO("mysql:dbname=test; host=localhost", "root", "root");
$sql = "INSERT INTO tasks (name, task) VALUES (:name, :task)";
$statement = $db->prepare($sql);
$statement->execute($addData);
}
if(isset($_POST["name"])):
$namePost = trim($_POST["name"]);
$namePost = strip_tags($namePost);
$namePost = htmlspecialchars($namePost,ENT_QUOTES);
$namePost = stripslashes($namePost);
endif;
Answer the question
In order to leave comments, you need to log in
WOULD NOT WANT.
Throw all these idiotic "millstones" in the trash.
Instead, it's better to make a normal function out of that hellish spaghetti you have now.
function addTask($db, $name, $task){
$sql = "INSERT INTO tasks (name, task) VALUES (?,?)";
$statement = $db->prepare($sql);
$statement->execute([$name, $task]);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question