Autocomplete html sql form

0

Well, I'm creating a system for the control of dining rooms, I'm really new to this, however I like to learn, I explain my problem I have a bar code reader reads a "card" and inserts the code into an input , I would like that when reading the card and inserting that code I will look for it in the database and autocomplete the data of that employee in other input, it will show me its information and also insert a record of food check in my database, to continued I describe the code as I have written it:

<?php
/*-------------------------
Autor: INNOVAWEBSV
Web: www.innovawebsv.com
Mail: [email protected]
---------------------------*/
session_start();
if (!isset($_SESSION['user_login_status']) AND 
$_SESSION['user_login_status'] != 1) {
    header("location: login.php");
    exit;
    }

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
$active_facturas="active";
$active_productos="";
$active_clientes="";
$active_usuarios="";    
$title="Facturas | Simple Invoice";
if(isset($_POST['grabar'])){

    $no_emp= $_POST['no_emp'];
}
$query_empresa=mysqli_query($con,"select * from empleados where 
no_emp='$no_emp'");
$row=mysqli_fetch_array($query_empresa);
?>

This above is the beginning of the code where is the connection to the database and the verification that the user starts session, then a query to store data in "row" variables.

In the HTML code is the following:

<!DOCTYPE html>
<html lang="en">
  <head>
    <?php include("head.php");?>


  </head>
  <body>
    <?php
    include("navbar.php");
    ?> 
    <div class="container">
      <div class="row">
        <div class="panel panel-danger">
            <div class="panel-heading">
              <h3 class="panel-title"><i class='glyphicon glyphicon-cog'></i> Configuración</h3>
            </div>
            <div class="panel-body">
      <form method="post" id="perfil">
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 toppad" >



            <div class="panel-body">
              <div class="row">

              <form class="form-horizontal" role="form"  id="datos_cotizacion">

                        <div class="form-group row">
                            <label for="q" class="col-md-2 control-label">Departamento o # de empleado</label>
                            <div class="col-md-5">
                                <input type="text" class="form-control" id="q" placeholder="Nombre del departamento # de empleado" onkeyup='load(1);'>
                            </div>



                            <div class="col-md-3">
                                <button type="button" class="btn btn-default" onclick='load(1);'>
                                    <span class="glyphicon glyphicon-search" ></span> Buscar</button>
                                <span id="loader"></span>
                            </div>

                        </div>


            </form>
            <form name="noemp" method="post">
                <div class="col-md-3 col-lg-3 " align="center"> 
                <div id="load_img">
                    <img class="img-responsive" src="<?php echo $row['img_emp'];?>" alt="Logo">

                </div>
                <br>                
                    <div class="row">
                    </div>
                </div>
                <div class=" col-md-9 col-lg-9 "> 
                  <table class="table table-condensed">
                    <tbody>
                      <tr>
                        <input type="hidden" name="id_perfil" value="<?php echo $_SESSION['user_id']?>">
                      </tr>
                      <tr>
                        <td class='col-md-3'>No Emp:</td>
                        <td><input type="text" class="form-control input-sm" name="no_emp" id="no_emp" value="" required></td>
                      </tr>
                      <tr>
                        <td>Nombre:</td>
                        <td><input type="text" class="form-control input-sm" name="nombre_emp" value="<?php echo $row['nombre_emp']?>" readonly></td>
                      </tr>
                      <tr>
                        <td>Departamento:</td>
                        <td><input type="text" class="form-control input-sm" name="dep_emp" value="<?php echo $row['dep_emp']?>" readonly></td>
                      </tr>
                      <tr>
                        <td>Confidencialidad:</td>
                        <td><input type="text" class="form-control input-sm" name="empresa_emp" value="<?php echo $row['empresa_emp']?>" readonly></td>
                      </tr>
                      <tr>
                        <td>Fecha de Ingreso:</td>
                        <td><input type="text" class="form-control input-sm" name="fecha" value="<?php echo date('d-M-Y',strtotime($row['ing_emp'])) ?>" readonly></td>
                      </tr>



                    </tbody>
                  </table>

                  </form>
                </div>
                <div class='col-md-12' id="resultados_ajax"></div><!-- Carga los datos ajax -->
              </div>
            </div>



                            <button type="submit" class="hidden" name="grabar"><i class="glyphicon glyphicon-refresh"></i> Actualizar datos</button>




          </div>
        </div>
        </form>

                <div id="resultados"></div><!-- Carga los datos ajax -->
                <div class='outer_div'></div><!-- Carga los datos ajax -->
            </div>
        </div>  

    </div>
    <hr>
    <?php
    include("footer.php");
    ?>
    <script type="text/javascript" src="js/VentanaCentrada.js"></script>
    <script type="text/javascript" src="js/checadas.js"></script>
    <script type="text/javascript" src="js/bootstrap-filestyle.js"> </script>
<script>
$( "#perfil" ).submit(function( event ) {
  $('.guardar_datos').attr("disabled", true);

 var parametros = $(this).serialize();
     $.ajax({
            type: "POST",
            url: "ajax/registro_checadas.php",
            data: parametros,
             beforeSend: function(objeto){
                $("#resultados_ajax").html("Mensaje: Cargando...");
              },
            success: function(datos){
            $("#resultados_ajax").html(datos);
            $('.guardar_datos').attr("disabled", false);

          }
    });
  event.preventDefault();
})






    </script>
    <script>
   $( "#perfil" ).submit(function( event ) {
    $('.guardar_datos').attr("disabled", true);

 var parametros = $(this).serialize();
     $.ajax({
            type: "POST",
            url: "ajax/buscar_checadas.php",
            data: parametros,
             beforeSend: function(objeto){
                $("#resultados_ajax").html("Mensaje: Cargando...");
              },
            success: function(datos){
            $("#resultados_ajax").html(datos);
            $('.guardar_datos').attr("disabled", false);

          }
    });
  event.preventDefault();
})






</script>
</body>
</html>

The detail is that I do not know how to make it look in the database with the code that is inserted in the employee number input (which is inserted by the barcode reader), I know I must put the variable in

$query_empresa=mysqli_query($con,"select * from empleados where no_emp='AQUI VA LA VARIABLE'"); $row=mysqli_fetch_array($query_empresa);

But I do not know how to store the input data in a variable to use it as a search criteria and in turn show me the data, I do not know if I explain, I leave a

  

file with my codes

, I hope you can help me and my head hurts from thinking so much haha, greetings!

    
asked by Abdiel Hernandez 16.04.2018 в 01:19
source

1 answer

0

To avoid SQL injection I would recommend something like this:

$sentencia = $con->prepare("select * from empleados where 
    no_emp = ?");
//binding de los parámetros (i se refiere a enteros)
$sentencia->bind_param("i", $no_emp );
$sentencia->execute();

$row = $sentencia->get_result();
//...
    
answered by 16.04.2018 в 21:44