I am pretty new to mysql and php and I am trying to set up some parameters to help me delete an entry from a table if the user presses the delete button. I currently have it set up to where the user can search the table by using department, name, or course number. Each delete statement is prepared by which search they are using.
The issue I am running into, is that when I create my delete statements, I do not know how to determine which the data being selected by the SELECT statement. A short snippet of code is displayed below.
if($_POST['radios'] == 0){
$sql = "SELECT * FROM classes where department LIKE '" . $_POST['search'] . "%';";
$select = 0;
$id = $sql;//problem area. Can't figure out how to pass the needed deparment info.
if($_POST['submit'] == "delete"){
if($select == 0){
mysqli_query($mysqli, "DELETE FROM classes WHERE department='".$id."'"); //need $id to match the correct department from table
mysqli_close($mysqli);
}
Edit: table
DROP TABLE IF EXISTS `classes`;
CREATE TABLE `classes` (
`name` varchar(255),
`department` varchar(255),
`course_id` varchar(255),
PRIMARY KEY(`course_id`),
`start` time,
`end` time,
`days` varchar(255)
);
Thanks for the help!