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.