Store name and image path to update php

0

I have a code that searches for me through the PLACA identifier some data, inside that data there is an image, I show it by means of the temporary one. up there all right, the problem comes when I want to update the data, sometimes I want to update the image and not others, but if I update any data the image is deleted, and I do not know how to store it. try naively putting <input type="file" name="imagen1" id="imagen1" value="<?php echo $fila[$ruta1]; ?>"> , but obviously it did not work. PDT: I know that the code is basic and little, but I did not want to extend it much, I also know that I should not use the mysql library, but that is what it is for now.

PHP

if(is_uploaded_file($_FILES["imagen6"]["tmp_name"])) {
  $ruta6= "FOTOS/".'_'.substr(sha1(rand(1,999)),0,-30).$_FILES["imagen6"]["name"];
  move_uploaded_file($_FILES["imagen6"]["tmp_name"], $ruta6);
} 

$updateSQL = sprintf("UPDATE huawei_parque_automotor SET PLACA=%s, imagen1=%s WHERE id=%s",
                   GetSQLValueString($_POST['PLACA'], "text"),
                   GetSQLValueString($ruta1, "text"),
                   GetSQLValueString($_POST['id'], "int"));

HTML

<?php 
$rst_informe = mysql_query("SELECT * FROM huawei_parque_automotor WHERE PLACA = '$PLACA'", $conexion);
$num_registros = mysql_num_rows($rst_informe);
?>

<?php 
  while ($fila=mysql_fetch_array($rst_informe))
  {    
?>

<td><input value="<?php echo $fila['PLACA']; ?>" type="text" name="PLACA" id="PLACA" /></td>
<td><img src="<?php echo $fila['imagen1']; ?>" alt="" width="125" height="125"/></td>

<?php
  }
?>

<input type="hidden" name="MM_update" value="form1" />
<input type="hidden" name="id" value="<?php echo $fila['id']; ?>" />   

<input type="submit" name="Actualizar" id="Actualizar" value="Actualizar"/>
    
asked by Anderviver 19.12.2017 в 21:58
source

2 answers

1

I do not know if it is the most optimal solution but what I would do is ask if the image comes, in case if I keep it if we do not keep the one that was previously:

if ($_FILES["imagen6"]["name"] != '') {
    if(is_uploaded_file($_FILES["imagen6"]["tmp_name"])) {
        $ruta6= "FOTOS/".'_'.substr(sha1(rand(1,999)),0,-30).$_FILES["imagen6"]["name"];
        move_uploaded_file($_FILES["imagen6"]["tmp_name"], $ruta6);
    } 

    $updateSQL = sprintf("UPDATE huawei_parque_automotor SET PLACA=%s, imagen1=%s WHERE id=%s",
                       GetSQLValueString($_POST['PLACA'], "text"),
                       GetSQLValueString($ruta1, "text"),
                       GetSQLValueString($_POST['id'], "int"));

}else{
    $updateSQL = sprintf("UPDATE huawei_parque_automotor SET PLACA=%s WHERE id=%s",
                       GetSQLValueString($_POST['PLACA'], "text"),
                       GetSQLValueString($_POST['id'], "int"));
}
    
answered by 20.12.2017 / 22:48
source
0

You can not forget the input must go inside the form tags and the tag must have the attribute enctype = 'multipart / form-data'

    
answered by 20.12.2017 в 22:55