How do I update records in the database?

1

I have this code what I'm looking for is to update the data of the registers but it does not work for me.

modifyingFormat.php

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Creando...</title>
    <link rel="stylesheet" type="text/css" href="estilos.css">
</head>
<body>
    <center>
        <h1>Actualizando Datos</h1>
        <form action="modificandoEstadoAmbu.php" method="post">
            <br><label>Placa: </label>
            <input type="text" name="placa" placeholder="placa" class="input-48" style="margin-left: 2%"></br>

            <br><label>Estado: </label>
            <input type="text" name="estado" placeholder="Disponibilidad" class="input-48"></br>

            <br><label>Tipo De Ambulancia:</label>
            <input type="text" name="tipo_Ambulancia" placeholder="Tipo De Ambulancia" class="input-48"></br>

            <br><input type="button" value="Volver!" onclick="location='http://localhost/Aeroasistencia/Administracion/editarCliente.php'" />

            <input type="submit" value="Actualizar" class="btn-enviar"></br>

    </center>

</body>
</html>

modifying EstadoAmbu.php

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


        $placa = $_POST["placa"];
        $estado = $_POST["estado"];
        $tipo_Ambulancia = $_POST["tipo_Ambulancia"];

        mysqli_query($conexion,"UPDATE ambulancia SET placa = '".$placa."', estado = '".$estado."', tipo_Ambulancia = '".$tipo_Ambulancia."' WHERE placa ='".$placa."'") or die("Error al actualizar");

?>
    
asked by Cristian Antonio Trujillo Gris 13.04.2018 в 15:35
source

1 answer

1

Try as follows:

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

    $placa = $_POST["placa"];
    $estado = $_POST["estado"];
    $tipo_Ambulancia = $_POST["tipo_Ambulancia"];

    mysqli_query($conexion,"UPDATE ambulancia SET placa = '$placa', 
    estado = '$estado', tipo_Ambulancia = '$tipo_Ambulancia' WHERE placa 
    ='$placa'") or die("Error al actualizar");?>

I would think that your problem is wanting to concatenate the fields, something that you can use to debug code is to use:

        var_dump($estado.'-'.$placa.'-'.$tipo_Ambulancia);exit();

before doing the update only to see what value the variables carry. and then you delete it or comment it and you must fucnionar.

    
answered by 13.04.2018 / 16:27
source