how do I update the records in a database?

1

I have this code, but it shows me this error:

Notice: Undefined variable: id_Funcionario in C:\xampp\htdocs\Aeroasistencia\aplicacionTruji\actualiza.php on line 26

I am making the query using the id of each person to show me the data and be able to update what is required of each person.

I'm using MySQL.

This is the form, whose file is modificarFuncionario.php :

<html>

<head>
    <title>Iniciar actualización.</title>
    <META name='robot' content='noindex, nofollow'>
</head>

<body>

    <div align="center">
        <table border="0" width="600" style="font-family: Verdana; font-size: 8pt" id="table1">
            <tr>
                <td colspan="2"><h3 align="center">Actualizacion de datos</h3></td>
            </tr>
            <form method="POST" action="modificarProceso.php">
                <tr>
                    <td width="50%">&nbsp;</td>
                    <td width="50%">&nbsp;</td>
                </tr>
                <tr>
                    <td width="50%">
                        <p align="center"><b>ID del funcionario a actualizar: </b></td>
                            <td width="50%">
                                <p align="center"><input type="text" name="id" size="20"></td>
                                </tr>
                                <tr>
                                    <td width="50%">&nbsp;</td>
                                    <td width="50%">&nbsp;</td>
                                </tr>
                                <tr>
                                    <td width="100%" colspan="2">
                                        <p align="center">
                                            <input type="submit" value="Iniciar actualización" name="btn-actulizar"></td>
                                            <input type="button" value="Volver de donde viniste!" onclick="history.back(-1)" />
                                        </tr>
                                    </form>
                                </table>
                            </div>

                        </body>

                        </html> 

Here I am doing the query, file modificarProceso.php :

<html>

<head>
    <title>Datos a actualizar.</title>
    <META name='robot' content='noindex, nofollow'>
</head>

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

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

$query = "  SELECT
                    id_Funcionario,
                    primer_Nombre,
                    segundo_Nombre,
                    primer_Apellido,
                    segundo_Apellido,
                    cargo_Funcionario,
                    telefono_Funcionario,
                    edad_Funcionario,
                    sexo_Funcionario
            FROM usuario
            WHERE id_Funcionario = '".$id."'";

/*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($id_Funcionario, $primer_Nombre, $segundo_Nombre, $primer_Apellido, $segundo_Apellido, $cargo_Funcionario, $telefono_Funcionario, $edad_Funcionario, $sexo_Funcionario);

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

    <div align='center'>
        <table border='0' width='600' style='font-family: Verdana; font-size: 8pt' id='table1'>
            <tr>
                <td colspan='2'><h3 align='center'>Actualice los datos que considere</h3></td>
            </tr>
            <tr>
                <td colspan='2'>En los campos del formulario puede ver los valores actuales,
                si no se cambian los valores se mantienen iguales.</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' name='id_funcinario' size='20' value='".$id_Funcionario."'></td>
            </tr>
            <tr>
                <td width='50%'><p align='center'><b>Primer Nombre :</b></td>
                <td width='50%'><p align='center'><input type='text' name='primer_Nombre' size='20' value='".$primer_Nombre."'></td>
            </tr>
            <tr>
                <td width='50%'><p align='center'><b>Segundo Nombre :</b></td>
                <td width='50%'><p align='center'><input type='text' name='segundo_Nombre' size='20' value='".$segundo_Nombre."'></td>
            </tr>
            <tr>
                <td width='50%'><p align='center'><b>Primer Apellido :</b></td>
                <td width='50%'><p align='center'><input type='text' name='primer_Apellido' size='20' value='".$primer_Apellido."'></td>
            </tr>
            <tr>
                <td width='50%'><p align='center'><b>Segundo Apellido :</b></td>
                <td width='50%'><p align='center'><input type='text' name='segundo_Apellido' size='20' value='".$segundo_Apellido."'></td>
            </tr>
            <tr>
                <td width='50%'><p align='center'><b>Cargo Funcionario :</b></td>
                <td width='50%'><p align='center'><input type='text' name='cargo_Funcionario' size='20' value='".$cargo_Funcionario."'></td>
            </tr>
            <tr>
                <td width='50%'><p align='center'><b>Telefono Funcionario :</b></td>
                <td width='50%'><p align='center'><input type='text' name='telefono_Funcionario' size='20' value='".$telefono_Funcionario."'></td>
            </tr>
            <tr>
                <td width='50%'><p align='center'><b>Edad Funcionario :</b></td>
                <td width='50%'><p align='center'><input type='text' name='edad_Funcionario' size='20' value='".$edad_Funcionario."'></td>
            </tr>
            <tr>
                <td width='50%'><p align='center'><b>Sexo Funcionario :</b></td>
                <td width='50%'><p align='center'><input type='text' name='sexo_Funcionario' size='20' value='".$sexo_Funcionario."'></td>
            </tr>
            <tr>
                <td width='50%'>&nbsp;</td>
                <td width='50%'>&nbsp;</td>
            </tr>
            <input type='hidden' name='id' value='$id'>
            <tr>
                <td width='100%' colspan='2'>
                <p align='center'>
                <input type='submit' value='Actualizar datos' name='B1'></td>
            </tr>
            </form>
        </table>
    </div>
    ";
    } 

}else{
    echo "Hubo un error en la consulta";
}
?>
    </body>
    </html>

Here I am doing the data update, file Actualiza.php :

<head>
    <title>Actualizacion completada.</title>
    <META name='robot' content='noindex, nofollow'>
</head>

<body>

    <?php
// Actualizamos en funcion del id que recibimos

    $id = $_POST['id'];

    $primer_Nombre = $_POST['primer_Nombre'];
    $segundo_Nombre = $_POST['segundo_Nombre'];
    $primer_Apellido = $_POST['primer_Apellido'];
    $segundo_Apellido = $_POST['segundo_Apellido'];
    $cargo_Funcionario = $_POST['cargo_Funcionario'];
    $telefono_Funcionario = $_POST['telefono_Funcionario'];
    $edad_Funcionario = $_POST['edad_Funcionario'];
    $sexo_Funcionario = $_POST['sexo_Funcionario'];
    $fecha = date("d-m-Y");

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


    $sSQL="UPDATE usuario SET ( id_Funcionario  ='".$id_Funcionario."', 
                                primer_Nombre ='".$primer_Nombre."', 
                                segundo_Nombre ='".$segundo_Nombre."', 
                                primer_Apellido ='".$primer_Apellido."', 
                                segundo_Apellido ='".$segundo_Apellido."', 
                                cargo_Funcionario ='".$cargo_Funcionario."', 
                                telefono_Funcionario ='".$telefono_Funcionario."', 
                                edad_Funcionario ='".$edad_Funcionario."', 
                                sexo_Funcionario ='".$sexo_Funcionario."')";

    if ($stmt = mysqli_prepare($conexion, $sSQL)) {

        /*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, "isssssiis", $id_Funcionario,$primer_Nombre,$segundo_Nombre,$primer_Apellido,$segundo_Apellido,$cargo_Funcionario,$telefono_Funcionario,$edad_Funcionario,$sexo_Funcionario);

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

        if (mysqli_stmt_error($stmt)){
            echo mysqli_stmt_errno($stmt);      
        }else{
            echo "Se actualizaron: ".mysqli_affected_rows($conexion);       
        }
        mysqli_stmt_close ($stmt);
    }else{

        echo "Hubo un error preparando la consulta";
    }       
    ?>

</body>

</html>
    
asked by Cristian Antonio Trujillo Gris 20.03.2018 в 13:45
source

3 answers

1

the problem is in the file Actualiza.php

you define

$id = $_POST['id'];

but do not use it, change to

$id_Funcionario =  $_POST['id'];

I hope it helps you

    
answered by 20.03.2018 в 13:53
0

Well first you have not defined the variable $ id_Funcion that is an error all are less that define it with the value of the post, I do not know if that is the error but it is one.

 $id = $_POST['id'];
    $primer_Nombre = $_POST['primer_Nombre'];
    $segundo_Nombre = $_POST['segundo_Nombre'];
    $primer_Apellido = $_POST['primer_Apellido'];
    $segundo_Apellido = $_POST['segundo_Apellido'];
    $cargo_Funcionario = $_POST['cargo_Funcionario'];
    $telefono_Funcionario = $_POST['telefono_Funcionario'];
    $edad_Funcionario = $_POST['edad_Funcionario'];
    $sexo_Funcionario = $_POST['sexo_Funcionario'];
    $fecha = date("d-m-Y");

esta no esta definida

**id_Funcionario  ='".$id_Funcionario."',** 

in the file updates.php

I should try this

  $id = $_POST['id'];
        $id_Funcionario = $_POST['id_Funcionario'];
        $primer_Nombre = $_POST['primer_Nombre'];
        $segundo_Nombre = $_POST['segundo_Nombre'];
        $primer_Apellido = $_POST['primer_Apellido'];
        $segundo_Apellido = $_POST['segundo_Apellido'];
        $cargo_Funcionario = $_POST['cargo_Funcionario'];
        $telefono_Funcionario = $_POST['telefono_Funcionario'];
        $edad_Funcionario = $_POST['edad_Funcionario'];
        $sexo_Funcionario = $_POST['sexo_Funcionario'];
        $fecha = date("d-m-Y");
    
answered by 20.03.2018 в 16:23
0

Well the name is like id_funcinario and it should be id_Funcionario

    <tr>
                <td width='50%'><p align='center'><b>Cedula: </b></td>
                <td width='50%'><p align='center'><input type='text' name='id_funcinario' size='20' value='".**$id_Funcionario**."'></td>
            </tr>

The variable with the change

 <td width='50%'><p align='center'><b>Cedula: </b></td>
                <td width='50%'><p align='center'><input type='text' name='id_Funcionario' size='20' value='".$id_Funcionario."'></td>
    
answered by 20.03.2018 в 16:41