Delete a row from my table

0

I want to delete a row from my table and I want to do it by means of a form in which I say the id of that row.

Why do you tell me that I have not defined the value? I mean, is not it picked up like this?

$valor = mysqli_real_escape_string($conexion, $_POST['idEliminar']);

Error

  

Notice: Undefined index: id Delete in C: \ xampp \ htdocs \ PHP_WEB_MMR \ P3 \ PHP \ delete.php on line 12

Code

<form action="PHP/eliminar.php">
  <input type="text" name="idEliminar" placeholder="ID del usuario a eliminar" required>
  <input type="submit" value="Eliminar">
</form>
<?PHP

    // Conectamos con la base de datos LOCAL
    $bd_host = "localhost"; 
    $bd_usuario = "root"; 
    $bd_password = ""; 
    $bd_base = "carrot";

    $conexion = mysqli_connect($bd_host, $bd_usuario, $bd_password, $bd_base);  

    // Recojo los datos del formulario - NOTAR EL USO DE LA FUNCIÓN DE ESCAPADO
    $valor = mysqli_real_escape_string($conexion, $_POST['idEliminar']);

    // Hacemos la consulta. En este caso queremos eliminar el usuario registrado
    $consulta = "DELETE FROM usuarios_pass WHERE id = $valor";

    $resultado = mysqli_query($conexion, $consulta);

    // Liberamos y cerramos conexión.
    //mysqli_free_result($resultado);
    //mysqli_close($conexion);
?>

As you can see, I had to comment

mysqli_free_result($resultado);

because as always I get an error, which as much as I read and explain to me I do not understand.

I know it must be very basic but the truth is that the PHP + SQL theme is making me a world.

Health!

    
asked by NEA 14.09.2018 в 19:09
source

2 answers

1

You are trying to get an POST index when your form does not specify it as POST

<form action="PHP/eliminar.php" method="POST">
  <input type="text" name="idEliminar" placeholder="ID del usuario a eliminar" required>
  <input type="submit" value="Eliminar">
</form>
    
answered by 14.09.2018 / 19:19
source
2

The form is sent by default with GET, but you are reading the $_POST .

You can pick up the value using $_REQUEST["idEliminar"]; instead.

    
answered by 17.09.2018 в 16:31