I am making input to this NOW because I had same problem. When I went tru answers given, it didn't help. Probably because the question didn't give full description of all associated scripts: HTML, Javascript, php etc.
Below is the structure of the correct php script I use to DELETE from database table
<?php
$servername = "localhost";
$username = "user";
$password = "0007";
$dbname = "CRCSystems";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$tblname = test_input($_POST["tblname"]);
$names = test_input($_POST["names"]);
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$sql = "SELECT * FROM $tblname WHERE Names = '$names'";
if (mysqli_query($conn, $sql)) {
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_row($result);
if ($row) {
$sql = "DELETE FROM $tblname WHERE Names = '$names'";
$result = mysqli_query($conn, $sql);
echo 1; //record deleted
} else {
echo 0; //record does not exist
}
}
mysqli_close($conn);
?>