<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
//connection to db
$conn = new mysqli("server information private");
//check the connection
if (!$conn) {
die("Connection failed:".msqli_connect_error());
}
session_start();
//set id to delete
$id = $_POST['id'];
//delete the row with the correct id
if($stmt = $conn->prepare("DELETE FROM costs WHERE id=?")) {
$stmt->bind_param("i", $id);
$stmt->execute();
}
} else {
echo "Error";
}
header("Location: ../costs.php");
?>
We look at HTML, CSS, and JavaScript within a web page as it is rendered in a browser. In other words, in its native form. We do not expect someone to post PHP code that needs to be interpreted as HTML, CSS or JS so we can work on a problem in any of those 3 formats. If you are posting PHP code, it should be because you have a question about the PHP code.
This is a continuation of an issue involving using PHP to process the deletion of the record, but the OP would now like to issue a warning to the user when they select the “Delete” button to ask them if they are sure that they would actually like to delete the record. This is where the JavaScript comes in.
This is what I would do, although I’m not sure it’s the best way to do it. I am far from being a JavaScript expert.