<?php
include_once('connect.php');
if(isset($_GET['sendForm'])){
$host = '127.0.0.1';
$username = 'root';
$password = '';
$db_name = 'library_db';
$charset = 'utf8mb4';
$options = [
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
\PDO::ATTR_EMULATE_PREPARES => false,
];
$dsn = "mysql:host=$host;db_name=$db_name;charset=$charset;port=$port";
$pdo = new \PDO($dsn, $username, $password, $options);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$link = mysqli_connect($host, $username, $password, $db_name);
$link->set_charset("utf8mb4");
$link = mysqli_connect($host, $username, $password, $db_name);
if (!$link) {
echo 'Не могу соединиться с БД. Код ошибки: ' . mysqli_connect_errno() . ', ошибка: ' . mysqli_connect_error();
exit;
}
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$books = $_POST['books'];
$term = $_POST['term'];
$country = $_POST['country'];
$subject = $_POST['subject'];
$query->execute("INSERT INTO `users` (`first_name`, `last_name`, `email`, `books`, `term`, `country`, `subject`) VALUES ($first_name, $last_name, $email, $books, $term, $country, $subject)");
$stmt = $link->prepare($query);
$stmt->bind_param($first_name, $last_name, $email, $books, $term, $country, $subject);
$stmt->execute();
if(mysqli_query($link, $stmt)){
echo "Запись добавлена!";
}
}
?>