Insert Mysql Database

Asked

Viewed 42 times

0

I need it to be inserted into the Mysql Database (table fotos) the path that is defined as $target_file_name. I believe the mistake is probably at the moment of INSERT.

Filing cabinet conexao.php:

try {

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

    //   echo "SUCESSO";

} catch (PDOException $erro) {

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

}
?>

Filing cabinet 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);

?>

  • You said the mistake is probably at the time of INSERT. But where is the INSERT in the code?

  • Sorry I was making a mistake and I took it out

  • and the form, ta as?

  • It is sent via Android the code is right is uploading and sending to folder, I just need to take this variable and insert in the bank

  • It follows updated code, it is taking the image of the ANDROID camera and inserting it into the UPLOAD folder OK ! I need him to insert in the comic book the way in case the variable.

  • INSERT FROM??? Wouldn’t be INSERT INTO?

  • Puts kkk was exactly that, I gave too soft I ended up not realizing now already this OK !

Show 2 more comments

1 answer

1


The error is in that line:

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

There is no INSERT FROM and yes INSERT INTO. Trade that line for that:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.