Ver Mensaje Individual
  #1 (permalink)  
Antiguo 12/04/2021, 20:11
pilucho
 
Fecha de Ingreso: noviembre-2004
Ubicación: NULL
Mensajes: 652
Antigüedad: 19 años, 5 meses
Puntos: 6
agregar un DELETE despues de If else...

hola amigos.

como puedo agregar una acción mas, en un solo archivo, es decir por medio de IF ELSE algo así como indica el código siguiente

en este archivo hay un UPDATE y INSERT, y necesito que se agregue un DELETE



Código PHP:
Ver original
  1. <?php  
  2.  $connect = mysqli_connect("localhost", "root", "", "myDB");  
  3.  if(!empty($_POST))  
  4.  {  
  5.       $output = '';  
  6.       $message = '';  
  7.       $name = mysqli_real_escape_string($connect, $_POST["name"]);
  8.       if($_POST["students_id"] != '')  
  9.       {  
  10.            $query = "UPDATE students SET name='$name' WHERE id='".$_POST["students_id"]."'";  
  11.            $message = 'Data Updated';  
  12.       }  
  13.       else  
  14.       {  
  15.            $query = "INSERT INTO students(name) VALUES('$name')";  
  16.            $message = 'Data Inserted';  
  17.       }
  18.  
  19.       // AGREGAR AQUI UN DELETE
  20.  
  21.       if(mysqli_query($connect, $query))  
  22.       {  
  23.            $output .= '<label class="text-success">' . $message . '</label>';  
  24.            $select_query = "SELECT * FROM students ORDER BY id DESC";  
  25.            $result = mysqli_query($connect, $select_query);  
  26.            $output .= '  
  27.                <table class="table">  
  28.                     <tr>  
  29.                          <th width="70%">Name</th>
  30.                     </tr>  
  31.           ';  
  32.            while($row = mysqli_fetch_array($result))  
  33.            {  
  34.                 $output .= '  
  35.                     <tr>  
  36.                          <td>' . $row["name"] . '</td>
  37.                     </tr>  
  38.                ';  
  39.            }  
  40.            $output .= '</table>';  
  41.       }  
  42.       echo $output;  
  43.  }  
  44.  ?>