-1
I’m 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 making the following mistake:
Parse error: syntax error, Unexpected ';' in C: xampp htdocs Site user functions.php on line 218
Line 218 is the query line
$query= "INSERT INTO produtos(ImagemProduto) VALUES ('$nome_img')";
even writing both lines of code by hand gives error
– José Gomes
The problem is in
if
. Missing one)
before opening the key{
.if(move_uploaded_file($_FILES['imagem']['tmp_name'], "images/Produtos/".$nome_img) ) {
– Leite
that solved the error , now is not registering
– José Gomes
You are returning "Error!"?
– Leite
You need to run the SQL query in the database. You can use
mysqli_query($query);
right after you set the variable$query
. https://www.w3schools.com/php/func_mysqli_query.asp http://php.net/manual/en/mysqli.query.php– Leite
Hello friend. first of all I fixed it here: products(Imagemproduto). Separates products from parenthesis products (Imagemproduto). See if it helps, if not maybe in the matter of mysqli Insert.
– Dávil André
@Dávilandré was not that still wrong when inserting the image
– José Gomes
@Joségomes changed the answer to give some more information. I think the problem you have now is that you are not connected to a database. I put some links for documentation that should help you.
– Leite
@Joségomes the problem now is the destination path of
move_uploaded_file
incorrect or the folder does not have the right permissions.– Leite
the way is right
– José Gomes