Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

331
Vistas
How do I create a DeleteVendor function that deletes a row from the database when an onClick button is pushed

I seem to be having an issue deleting rows from my database using a function I created called "DeleteVendor". I can get the Confirm box to pop up but the moment I add the php portion it stops.

<script text='language/javascript">

function DeleteVendor(vendor_id, vendor_name)
{
  if (confirm("Are you sure you want to delete " + vendor_name))
  {
    // perform delete operation
    <?php
      $conn = new mysqli($servername, $username, $password, $dbname);
      // Check connection
      if ($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);
      }
      $sql = "SELECT * FROM vendors order by vendor_id";
      $result = $conn->query($sql);
      if ($result->num_rows > 0) {
        $sql = "DELETE FROM vendors WHERE vendor_id = 'Delete'";
        
      }
    $conn->close();
    ?>
  }
}
</script>

Buttons:

<td style='text-align:center'>
<input style='border-color:#0000FF;background-color:#0000FF;color:#FFFFFF;height:25px;margin-right:15px' type='submit' onclick='EditVendor(" . $row["vendor_id"] . ")' value='Edit' />
<input style='border-color:FF0000;background-color:#FF0000;color:#FFFFFF;height:25px' type='button' onclick=\"DeleteVendor(" . $row["vendor_id"] . ", '" . $row["vendor_name"] . "')\" value='Delete' />
</td>

I've searched this site along with w3schools trying a few different methods mentioned but have had no luck. I've seen examples that use a "hidden" button in addition to the onClick button, when I tried this nothing happened still. Any help would be appreciated thank you.

about 4 years ago · Santiago Gelvez
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda