0
In the system I am developing has a form with a field where the user can attach an image.
After saving the form, the user wants to view the record including the image, so I thought about saving the image in a folder on the system and its directory in the database.
That’s my form page:
<form method="post" action="update-acidentes.php">
<fieldset>
<h3 class="subhead" style="color:#39b54a;">Clarificação do problema</h3>
<div class="form-field">
<h4> O que: </h4>
<select style="color:#9e9e9e;" name="OQUE" type="text" id="OQUE" aria-required="true" class="full-width">
<option>Clique aqui e selecione...</option>
<option>Acidente</option>
<option>Quase acidente</option>
<option>Trajeto</option>
<option>Incêndio</option>
<option>Acidente impessoal</option>
</select>
</div>
<h4> Quem </h4>
<div class="form-field">
<p style="font-size:20px;"> Nome </p>
<input style="color:#9e9e9e;" name="NOME" type="text" id="NOME" placeholder="Insira aqui o nome do colaborador" aria-required="true" class="full-width">
</div>
<div class="form-field">
<p style="font-size:20px;"> Descrição do evento </p>
<textarea style="color:#9e9e9e;" name="DESCRICAO" type="text" id="DESCRICAO" placeholder="Descreva o ocorrido" aria-required="true" class="full-width"></textarea>
</div>
<div class="form-field">
<p style="font-size:20px;"> Foto </p>
<input style="color:#9e9e9e;" name="FOTOA" type="file" id="FOTOA" aria-required="true" class="full-width">
</div>
<?php require_once('foto-acidente.php'); ?>
<div class="form-field">
<button type="submit" class="btn btn-primary btn-lg btn-block" style="background-color: #39b54a">Salvar</button>
</div>
</fieldset>
</form>
This is the page that saves the form in the bank:
<!--Update de acidentes-->
<?php
$oque = $_POST['OQUE'];
$nome = $_POST['NOME'];
$descricao = $_POST['DESCRICAO'];
$strcon = mysqli_connect('localhost','root','', 'banco') or die('Erro ao conectar ao banco de dados');
$sql = "INSERT INTO acidentes (OQUE, NOME, DESCRICAO ) VALUES ('$oque', '$nome', '$descricao')";
mysqli_query($strcon,$sql) or die("Erro ao tentar cadastrar registro" . mysqli_error($strcon));
mysqli_close($strcon);
if(isset($_FILES["FOTOA"])){
$arquivo = $_FILES["FOTOA"];
//diretorio dos arquivos
$pasta_dir = "images/arquivosACIDENTES/";
// Faz o upload da imagem
$arquivo_nome = $pasta_dir . $arquivo["FOTOA"];
//salva no banco
move_uploaded_file($arquivo["FOTOA"], $arquivo_nome);
$query = "Insert into acidentes (IMAGEM) values ($arquivo_nome)";
}
echo '<script type="text/javascript">
alert("Salvo com Sucesso !");
window.history.go(-1);
</script>';
?>
When I save a new record, the saved message appears successfully and when I open the database really all the columns were saved except the image.
The folder I created to store the images is also empty.
Does anyone know what might be going on?
Perfect. Very explanatory, solved the problem. Thank you.
– Mariana Bayonetta