Answer the question
In order to leave comments, you need to log in
How to send data from HTML form to database?
Here is the code:
<?php
try {
$conn = new PDO(dsn: "mysql:host=localhost;dbname=Owl", username: 'root', password: 'root');
if(empty($_POST['name'])) exit("Поле не заполнено");
if(empty($_POST['surname'])) exit("Поле не заполнено");
$query = "INSERT INTO inquiries VALUES (NULL , :name, NOW())";
$msg = $conn->prepare($query);
$msg->execute(['name' => $_POST['name']]);
$msg_id = $conn->lastInsertId();
$query = "INSERT INTO inquiries_content VALUES (NULL , :surname, :inquiries_id NOW())";
$msg = $conn->prepare($query);
$msg->execute(['surname' => $_POST['surname'],'inquiries_id' => $msg_id]);
header(string: "Location: help.html");
}
catch (PDOException $e)
{
echo "Ошибка";
}
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question