Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

333
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda