i am currently creating a web page to delete data from a table using php by using name column in the table instead of ID. But it is not getting deleted when i give the input as event name.
<?php
session_start();
$servername = "localhost";
$username = "database_admin";
$password = "Veritasirum123";enter code here
$dbname = "workflow";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>
<?php
if(isset($_POST['submit'])){
$ename=$_POST["ename"];
$sql="DELETE from event where ename=$ename";
if ($conn->query($sql) === TRUE) {
echo '<script language="javascript">';
echo 'alert("Event Deleted Successfully")';
echo '</script>';
} else {
echo '<script language="javascript">';
echo 'alert("Event Deletion Failed")';
echo '</script>';
}
}
?>
please check this variable value :$ename=$_POST["ename"]; or try using this variable : $ename=$_GET["ename"];
or please past event name static and check it
It can be a issue with the value you are parsing.. or can be a issue with datatype.. check your passing value and remove it's any white spaces by using trim() funcion
$ename=trim($_POST["ename"]);
then if ename field is string then you have to put single quotes. like below
$sql="DELETE from event where ename='$ename'";