Notice: Undefined variable: tmp_name in C:

0

Good morning Friends StackOverflow

I have the following error when saving a form with an image, the error I receive:

  

\ xampp \ htdocs \ stock \ ajax \ new_categoria.php on line 20   The catalog has been successfully entered.

I want to save the image in a server folder and in the BD I want to save the route. In the html table it shows me the path of the image, but it does not save the image in the folder.

This is the code:

new_category.php

<?php
include('is_logged.php');//Archivo verifica que el usario que intenta acceder a la URL esta logueado
/*Inicia validacion del lado del servidor*/

if(empty($_POST['nombre'])) {
       $errors[] = "Nombre vacío";  
    } else if (!empty($_POST['nombre'])){
    /* Connect To Database*/
    require_once ("../config/db.php");//Contiene las variables de configuracion para conectar a la base de datos
    require_once ("../config/conexion.php");//Contiene funcion que conecta a la base de datos
    // escaping, additionally removing everything that could be (html/javascript-) code


    $nombre=mysqli_real_escape_string($con,(strip_tags($_POST["nombre"],ENT_QUOTES)));
    $descripcion=mysqli_real_escape_string($con,(strip_tags($_POST["descripcion"],ENT_QUOTES)));                  
    $date_added=date("Y-m-d H:i:s");
    $foto=isset($_FILES["foto"]);
        if ($foto["type"] == "img/jpg" OR $foto["type"] == "img/jpeg" );
            $ruta = "../img".md5($foto["tmp_name"]).".jpg"; 
            move_uploaded_file($tmp_name, $ruta);  

    $sql="INSERT INTO categorias (foto, nombre_categoria, descripcion_categoria,date_added) VALUES ('$ruta','$nombre','$descripcion','$date_added')";
    $query_new_insert = mysqli_query($con,$sql);
        if ($query_new_insert){

            echo "El catalogo ha sido ingresada satisfactoriamente.";
        } else{
            $errors []= "Lo siento algo ha salido mal intenta nuevamente.".mysqli_error($con);
        }
    } else {
        $errors []= "Error desconocido.";
    }



    if (isset($errors)){

        ?>
        <div class="alert alert-danger" role="alert">
            <button type="button" class="close" data-dismiss="alert">&times;</button>
                <strong>Error!</strong> 
                <?php
                    foreach ($errors as $error) {
                            echo $error;
                        }

                    ?>
        </div>
        <?php
        }
        if (isset($messages)){

            ?>
            <div class="alert alert-success" role="alert">
                    <button type="button" class="close" data-dismiss="alert">&times;</button>
                    <strong>¡Bien hecho!</strong>
                    <?php
                        foreach ($messages as $message) {
                                echo $message;
                            }
                        ?>
            </div>
            <?php
        }

?>

The file of the form

registration_categories.php

    <?php
    if (isset($con))
    {
?>
<!-- Modal -->
<div class="modal fade" id="nuevoCliente" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel"><i class='glyphicon glyphicon-edit'></i> Agregar nuevo catalogo</h4>
      </div>
      <div class="modal-body">
      <form class="form-horizontal" method="post" id="guardar_categoria" name="guardar_categoria" enctype="multipart/form-data">
        <div id="resultados_ajax"></div>

         <div class="form-group">
            <label for="foto" class="col-sm-3 control-label">Foto</label>
            <div class="col-sm-8">
              <input type="file" class="form-control" id="foto" name="foto">
            </div>
          </div>

          <div class="form-group">
            <label for="nombre" class="col-sm-3 control-label">Nombre</label>
            <div class="col-sm-8">
              <input type="text" class="form-control" id="nombre" name="nombre" required>
            </div>
          </div>


          <div class="form-group">
            <label for="descripcion" class="col-sm-3 control-label">Descripción</label>
            <div class="col-sm-8">
                <textarea class="form-control" id="descripcion" name="descripcion"   maxlength="255" ></textarea>

            </div>
          </div>







      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
        <button type="submit" class="btn btn-primary" id="guardar_datos">Guardar datos</button>
      </div>
      </form>
    </div>
  </div>
</div>
<?php
    }
?>

And this is the js file that the AJAX has:

$( "#guardar_categoria" ).submit(function(event){
    $('#guardar_datos').attr("disabled", true); 

var datos = new FormData($("#guardar_categoria")[0])
$("resultados_ajax").html("Mensaje: Cargando...")
$.ajax({
    url: 'ajax/nueva_categoria.php',
    type: 'POST',
    data: datos,
    contentType: false,
    processData: false,
    success: function(datos){
        $("#resultados_ajax").html(datos);
        $('#guardar_datos').attr("disabled", false);
        load(1);
    }
});
event.preventDefault()
})

Attached image of the error and in the background you can see that it saves the route and there I want to see the image.

Thanks for your help.

    
asked by Jeinner Marulanda 26.07.2017 в 17:47
source

0 answers