0
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]);
}

Вот ошибка:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1

Можете мне пальцем ткнуть где ошибка у меня ?

1 ответ 1

1
  1. Вам не нужно обрамлять параметры апострофами
  2. Вам нужно закрыть скобку после VALUES
$sql = "INSERT INTO `user277145_jess`.`otzivi` (`id`, `name`, `text`, `product`, `time`) VALUES (NULL, :name, :text, :product, ".time().");";
5
  • Спасибо, заработало, только теперь вылезла другая: SQLSTATE[HY000]: General error: 2053
    – cr1gger
    25 янв 2017 в 13:42
  • 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>Ошбика при выполнение запроса QUERY</b>: ' . $e->getMessage()); } }
    – cr1gger
    25 янв 2017 в 13:43
  • @cr1gger Если мой ответ решил Вашу проблему, отметьте его как правильный. Если у Вас есть новые вопросы, то создайте новую тему 25 янв 2017 в 13:48
  • ну ты и злодей...
    – cr1gger
    25 янв 2017 в 13:51
  • @cr1gger Я не злодей. Этот ресурс предназначен для того, чтобы другие люди могли находить здесь ответы 25 янв 2017 в 13:56

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.