0
Hello people first ask me here on the website sorry if I end up doing something wrong. My doubt is the following, when I will make the change of the data of a product always have to put the photo in the input field because if I do not put my code ends up changing the name in the database leaving it empty, how do I change the form data without always having to load the image?
Follow the update code
<?php
session_start();
include_once("seguranca.php");
include_once("conexao.php");
if(isset($_FILES['imagem']))
{
date_default_timezone_set("Brazil/East"); //Definindo timezone padrão
$ext = strtolower(substr($_FILES['imagem']['name'],-4)); //Pegando extensão do arquivo
$new_name = date("Y.m.d-H.i.s") . $ext; //Definindo um novo nome para o arquivo
$dir = '../imagens/'; //Diretório para uploads
move_uploaded_file($_FILES['imagem']['tmp_name'], $dir.$new_name); //Fazer upload do arquivo
}
$id = $_POST["id"];
$nome = $_POST["nome"];
$preco = $_POST["preco"];
$divide = $_POST["divide"];
$tamanho = $_POST["tamanho"];
$marca_id = $_POST["marca_id"];
$cor_id = $_POST["cor_id"];
$situacao_id = $_POST["situacao_id"];
$cate_id = $_POST["cate_id"];
$imagem = $new_name;
$query = mysql_query("UPDATE produtos set nome ='$nome', preco = '$preco', divide = '$divide', tamanho = '$tamanho', marca_id = '$marca_id', cor_id = '$cor_id', situacao_id = '$situacao_id', cate_id = '$cate_id', foto = '$imagem' WHERE id='$id'");?>
html is like this
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Imagem:</label>
<div class="col-sm-10">
<input type="file" class="form-control" name="imagem" placeholder="" value="">
</div>
</div>
Thank you and if there is something wrong in my question speak to me newbie here.
Do an if. If $_files is empty, run another update query without the part that updates the image. Or when you select the information you will edit, load a separate input field with the file name. Then send this name to the database. Generally use other alternative with Javascript.
– Willian Coqueiro
Thanks @Williancoqueiro I’ll do it, I’m new in this area, a little layy yet.
– Everton Figueiredo
I understood right. If $image is empty executes another query without updating her name in the bank.
– Willian Coqueiro
It gave yes friend, I will do the If here and I return already speaking the result
– Everton Figueiredo
Answer she is put solution or I answer and put solution.
– Willian Coqueiro