PHP syntax error when inserting an image

-1

I am inserting an image into the database with the following code

$nome_img = $_FILES['imagem']['name'];
if(move_uploaded_file($_FILES['imagem']['tmp_name'], "images/Produtos/".$nome_img){
   $query=  "INSERT INTO produtos(ImagemProduto) VALUES ('$nome_img'))";
}else{
   echo "Erro!";
}

And you're giving me the following error:

  

Parse error: syntax error, unexpected ';' in C: \ xampp \ htdocs \ Site \ user \ functions.php on line 218

Line 218 is the query

$query=  "INSERT INTO produtos(ImagemProduto) VALUES ('$nome_img')";
    
asked by anonymous 08.06.2018 / 13:02

2 answers

0

So, apparently it's correct, but to make a mistake, it's probably related to " and ' .

I tried to write the line again, without copying / pasting, you could even try using a form other than string interpolation , so

$query = "INSERT INTO produtos(ImagemProduto) VALUES ('" . $nome_img . "')";

or

$query = "INSERT INTO produtos(ImagemProduto) VALUES ('{$nome_img}')";

EDIT

The problem is actually missing the ) of if just above the line where the $query variable is defined.

More, you also need to add the statement to run the query in the database, right on the next line where you are defining the variable $query .

$result = mysqli_query($db, $query);

    
08.06.2018 / 13:15
0

Your error is in the upload line:

if(move_uploaded_file($_FILES['imagem']['tmp_name'], "images/Produtos/".$nome_img){

It's missing a ) , should be:

if(move_uploaded_file($_FILES['imagem']['tmp_name'], "images/Produtos/".$nome_img)){
    
08.06.2018 / 15:48