B
B
Bionis2021-07-03 12:18:35
PHP
Bionis, 2021-07-03 12:18:35

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 "Ошибка";
}
?>

When I enter data and try to send it to the database, I see this "Parse error: syntax error, unexpected ':', expecting ')' in C:\laragon\www\Site\form.php on line 3" - everything is in this line right like, take a look, maybe I don’t see something.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question