delete php record


I do not understand why this code is not executed to delete a user by entering an email:

<div class="lista-usuarios">
<h2>Lista de usuarios: </h2> <br>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <input type="text" name="email" id="email">
    <button type="submit" name="borrar_usuario">Eliminar</button>


foreach ($usuarios as $value) { 
  if ($value === '[email protected]') {?>
     <li id=<?php echo $value; ?> class='usuario'> <?php echo $value ?> </li> <?php }else{ ?>
     <li id=<?php echo $value; ?> class='usuario'> <?php echo $value ?> 
     <a href="#" onclick='preguntar(<?php echo $value; ?>)'>Eliminar</a>

$mysqli = new mysqli($host,$user,$pass,$db);

if (isset($_POST['borrar_usuario'])) {
    if (isset($_POST['email'])) {
        $sql_borrar = 'DELETE FROM usuarios where email='. $_POST['email'] .'';
asked by Oscar Plumariega 27.12.2018 в 18:35

1 answer


Here there may be a syntax error. The quotes.

 $sql_borrar = 'DELETE FROM usuarios where email='. $_POST['email'] .'';

It should be like that.

 $sql_borrar = "DELETE FROM usuarios where email='. $_POST['email'] .'";

or so.

 $sql_borrar = 'DELETE FROM usuarios where email=". $_POST["email"] ."';

You have to be careful with the single quotes in php, I hope it helps you.

answered by 27.12.2018 в 20:56