how do I consult my database?

0

I'm trying to make a query from my database

But he shows me the following error:

  

Notice: Undefined index: id in   C: \ xampp \ htdocs \ Aero assistance \ Administration \ Client edition.php on   line 10

This is my code:

<html>

<head>
    <title>Consultando Cliente...</title>
    <META name='robot' content='noindex, nofollow'>
</head>

<?php 
echo "<body>";
$id = $_POST['id'];

$conexion =  mysqli_connect("localhost", "root","admin123","database");

$query = "  SELECT NIT, nombre_Cliente FROM cliente WHERE nombre_Cliente = ?";

/*Prepara la setencia SQl para su ejecucion*/
if ($stmt = mysqli_prepare($conexion, $query)) {

    /*Agrega variables a una sentencia preparada como parametros*/
    /* ligar parámetros para marcadores */
    /*IMPORTANTE: Si id no es numérico en la base de datos, cambia la i por una s*/
    mysqli_stmt_bind_param($stmt, "i", $id);

    /* Ejecuta una consulta preparada */
    mysqli_stmt_execute($stmt);

    /*Se transfiere los  resultados de la ultima consulta*/
    $stmt->store_result();

    /* Vincula las variables a una setencia preparada para el almacenamineto de result */
    $stmt->bind_result($NIT, $nombre_Cliente);

    while ($stmt->fetch()) {
        echo "

    <div align='center'>
        <table border='1' width='600' style='font-family: Verdana; font-size: 8pt' id='table1'>
            <tr>
                <td colspan='2'><h3 align='center'>Consultando funcionarios</h3></td>
            </tr>
            <tr>
                <td colspan='2'>En los campos del formulario puede ver los valores actuales,
                de los funcionarios.</td>
            </tr>
            <form method='POST' action='actualiza.php'>
            <tr>
                <td width='50%'>&nbsp;</td>
                <td width='50%'>&nbsp;</td>
            </tr>
            <tr>
                <td width='50%'><p align='center'><b>Cedula: </b></td>
                <td width='50%'><p align='center'><input type='text' disabled=”disabled”  name='id_funcinario' size='20' value='".$NIT."'></td>
            </tr>
            <tr>
                <td width='50%'><p align='center'><b>Primer Nombre :</b></td>
                <td width='50%'><p align='center'><input type='text' disabled=”disabled” name='primer_Nombre' size='20' value='".$nombre_Cliente."'></td>
            </tr>
            </form>
        </table>
        <input type='button' value='Volver de donde viniste!' onclick='history.back(-2)' /> 
    </div>
    ";
    } 

}else{
    echo '<script>
                    alert("El cliente no existe");
         </script>';
}
</body>
</html>
    
asked by Cristian Antonio Trujillo Gris 26.03.2018 в 22:30
source

4 answers

0

The problem you have is that when you load the page .. The variables for POST do not exist ..

The recommendation is that you make a validation before

if(isset($_POST) && $_POST != NULL){
     //Aqui va tu codigo php de consulta a la base de datos
}
    
answered by 26.03.2018 в 22:35
0

Your variable "id" is not defined in null, make sure you are bringing some data from the previous form.

  

if (isset ($ _ POST ['id'])) {
  // if you have data
  } else {   // has no data   }

    
answered by 27.03.2018 в 00:13
0

You have an error in $ id = $ _POST ['id']

    
answered by 27.03.2018 в 04:26
0

the error is in

  

$ id = $ _POST ['id'];

check if you are sending the id correctly

    
answered by 27.03.2018 в 00:00