When displaying a query in a table I create these three fields for the user to update to the line that shows the query data:
<?php
$tabela1 .= '<td> <input type="file" name= "Imagem['.$rows_cursos['Id'].']" value="'.$rows_cursos['Imagem'].'"></td>';
$tabela1 .= '<td> <input type="text" name= "Tratamento['.$rows_cursos['Id'].']" value="'.$rows_cursos['Tratamento'].'"></td>';
$tabela1 .= '<td> <input type="radio" name= "Id['.$rows_cursos['Id'].']" value="Pendente"> Pendente <input type="radio" name= "Id['.$rows_cursos['Id'].']" value="Concluido">Concluido</td>';
?>
In this next step, I keep the path of the image in this way, but it does not save the complete path, it only saves the image name and the format "DSCF2712.JPG":
<?php
if(isset($_POST['registar']))
{
$servername = "xxx.xxx.x.xx";
$username = "xxxxx";
$password = "xxxxxxx";
$dbname = "xxxxxxxx";
$conn = new mysqli($servername, $username, $password, $dbname);
$conn->set_charset('utf8');
$registro = $_POST['Id'];
$imagem = $_POST['Imagem'];
$tratamento = $_POST['Tratamento'];
foreach($registro as $Id => $estado) {
$conn->query("UPDATE RegistoManutencao SET Estado='$registro[$Id]', Imagem = '$imagem[$Id]', Tratamento = '$tratamento[$Id]' WHERE Id='".$Id."'");
}
}
?>
I've been searching and from what I realized the ideal is just save the name of the image and the extension, as I have, but now how do I show it? I'm doing it this way:
<?php
$result_cursos = "SELECT centrodb.RegistoManutencao.Imagem FROM centrodb.RegistoManutencao";
$resultado_cursos = mysqli_query($conn, $result_cursos);
$tabela1 .= '<div style="float: center" table align="center">';
$tabela1 .= '<table border="5">';
$tabela1 .= '<tr>';
$tabela1 .='<thead>';
$tabela1 .= '<tr>';
$tabela1 .= '<th>Imagem</th>';
$tabela1 .= '</tr>';
$tabela1 .='</thead>';
$tabela1 .='<tbody>';
while($rows_cursos = mysqli_fetch_array($resultado_cursos)) {
$tabela1 .= '<tr>';
$tabela1 .= '<td><img src="' .$rows_cursos['Imagem']. '" /></td>';
$tabela1 .= '</tr>';
}
$tabela1 .= '</tr>';
$tabela1 .='</tbody>';
$tabela1 .= '</table>';
$tabela1 .= '</div>';
echo $tabela1;
?>
And the result is this, does not show the image, but if you do inspect it shows the name and the extension that is in the database:
I think the problem is not being able to find the full path of the image