Insert MySQL Database

0

I need to insert into the MySQL Database (table fotos ) the path that is set to $target_file_name . I believe that the error is probably at the time of INSERT .

File conexao.php :     

try {

    $PDO = new PDO($dsn, $usuario, $senha);

    //   echo "SUCESSO";

} catch (PDOException $erro) {

    //echo "ERRO: " .$erro.getMessage();
    //  echo "conexao_erro";
    exit;

}
?>

File upload_image.php :

<?php

include "conexao.php";



$target_dir = "upload/";
$target_file_name = $target_dir .basename($_FILES["file"]["name"]);
$response = array();

if (isset($_FILES["file"])) 
{
 if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file_name)) 
 {
  $success = true;
  $message = "Sucesso !";

  $sql_insert = "INSERT FROM fotos (foto_url) VALUES (:TARGET_FILE_NAME)";   
     $stmt = $PDO ->prepare($sql_insert);
     $stmt -> bindParam(':TARGET_FILE_NAME', $target_file_name);
     $stmt -> execute();


 }
 else
 {
  $success = false;
  $message = "Erro no upload !";
 }
}
else
{
 $success = false;
 $message = "Favor inserir arquivo !";
}

$response["success"] = $success;
$response["message"] = $message;
echo json_encode($response);

?>
    
asked by anonymous 11.11.2018 / 21:38

1 answer

1

The error is in this line:

$sql_insert = "INSERT FROM fotos (foto_url) VALUES (:TARGET_FILE_NAME)";

There is no INSERT FROM and yes INSERT INTO . Change this line to this:

$sql_insert = "INSERT INTO fotos (foto_url) VALUES (:TARGET_FILE_NAME)";
    
11.11.2018 / 23:56