if (!empty($_POST['message']) && !empty($_POST['user_name'])) { $name = $_POST['user_name']; $text = $_POST['message']; $product = (is_numeric($_POST['product']) && !empty($_POST['product'])) ? $_POST['product']:NULL; $sql = "INSERT INTO `user277145_jess`.`otzivi` (`id`, `name`, `text`, `product`, `time`) VALUES (NULL, ':name', ':text', :product, ".time().";"; //die($sql); $resutl = $mysql->query($sql, [':name'=> $name, ':text' => $text, ':product' => $product]); } 

Here is the error:

SQLSTATE [42000]: Syntax error or access violation: 1064 SQL syntax; check it out at the line.

Can I poke a finger where I have a mistake?

    1 answer 1

    1. You do not need to frame parameters with apostrophes.
    2. You need to close the bracket after VALUES
     $sql = "INSERT INTO `user277145_jess`.`otzivi` (`id`, `name`, `text`, `product`, `time`) VALUES (NULL, :name, :text, :product, ".time().");"; 
    • Thanks, it worked, only now another one got out: SQLSTATE [HY000]: General error: 2053 - cr1gger
    • public function query ($ sql, $ params = []) {try {$ sth = $ this-> db-> prepare ($ sql); $ sth-> execute ($ params); return $ sth-> fetchAll (PDO :: FETCH_OBJ); } catch (PDOException $ e) {die ('<b> Oshbika at QUERY query execution </ b>:'. $ e-> getMessage ()); }} - cr1gger
    • @ cr1gger If my answer solved your problem, mark it as correct. If you have new questions, then create a new topic - Anton Shchyrov
    • Well, you and the villain ... - cr1gger
    • @ cr1gger I am not a villain. This resource is designed so that other people can find the answers here - Anton Shchyrov