Script on ajax + php with pdo requests to the server, the picture falls, but there is no data in the database. i.e. directory and file name

This error occurs

Fatal error : Uncaught exception 'PDOException' with message 'SQLSTATE [42000]: Syntax error or access violation: 1064 You can have an error in your SQL syntax; If you’re on the right line, you’ll find out what you’re trying to use. For example, you’ll find out what you’re using for the right syntax to use the 'WHERE login = NULL' at line 1 'in / home / a0031620 / domains : 43

Stack trace:

# 0 /home/a0031620/domains/yourdosug.ru/public_html/saratov/registration/1/upload.php(43): PDOStatement-> execute ()

# 1 {main} thrown in /home/a0031620/domains/yourdosug.ru/public_html/saratov/registration/1/upload.php on line 43

Then here is the query script to the database mr

$sqlimage = "INSERT INTO users(catalog, filename) VALUES(:catalog, :filename) WHERE login = :login"; $stmtimg = $pdo->prepare($sqlimage); $stmtimg->bindParam(':catalog', $uploaddire, PDO::PARAM_STR); $stmtimg->bindParam(':filename', $comma_separated, PDO::PARAM_STR); $stmtimg->bindParam(':login', $_POST['login'], PDO::PARAM_STR); $stmtimg->execute(); 

and just in case the whole code

 <?php require_once( $_SERVER['DOCUMENT_ROOT'] . '/registration/1/my_room/php/session.php'); require_once( $_SERVER['DOCUMENT_ROOT'] . '/bd.php'); header('Content-Type: application/json; charset=utf-8'); if(isset($_FILES)) { //пролистываем весь массив изображений по одному $_FILES['file']['name'] as $k=>$v $error = array(); foreach($_FILES['file']['name'] as $k=>$v){ $uploaddir = 'images/'; $uploadfile = $uploaddir.basename($_FILES['file']['name'][$k]); // Копируем файл из каталога для временного хранения файлов: if (!copy($_FILES['file']['tmp_name'][$k], $uploadfile)) { $error[] = "<div class='dannye'><h3>Ошибка! Не удалось загрузить файл на сервер!</div></h3>"; } } if(count($error) == 0) { //$uploadfiles = explode(',', $uploadfilee); //$getMime = $_FILES['uploadfile']['name'][$k]; $uploaddire = $uploaddir; $comma_separated = implode(',', $uploadfilee); $sqlimage = "INSERT INTO users(catalog, filename) VALUES(:catalog, :filename) WHERE login = :login"; $stmtimg = $pdo->prepare($sqlimage); $stmtimg->bindParam(':catalog', $uploaddire, PDO::PARAM_STR); $stmtimg->bindParam(':filename', $comma_separated, PDO::PARAM_STR); $stmtimg->bindParam(':login', $_POST['login'], PDO::PARAM_STR); $stmtimg->execute(); /* $sqlimage = $pdo->prepare("INSERT INTO users(catalog, filename) VALUES(:catalog, :filename) WHERE login = :login"); $sqlimage->execute(array( "catalog" => $uploaddire, "filename" => $comma_separated, "login" => $_POST['login'] ));*/ //выводим результат\ if (isset($sqlimage)) { echo 1; } elseif (!$sqlimage) { echo 0; } else { echo "ничего не пойму"; } } elseif (count($error) > 0){ echo json_encode($error); } } 

    2 answers 2

    Remove the INSERT WHERE login = :login request WHERE login = :login , the WHERE clause is not defined for the INSERT construct.

    • removed nothing has changed - Koly
    • @Koly $ stmtimg-> bindParam (': login', $ _POST ['login'], PDO :: PARAM_STR); - also remove or render it in INSERT VALUES - Firepro

    The error indicated: WHERE login = NULL

    Check the names of the inps in the form, and be sure to check if there is any info in the keys of the array you need.

     if (!$_POST['login']){ exit("Empty Login!"); }