Question: trying to get this php form from when the user clicks the delete button it deletes the subjects from the list this is the code
trying to get this php form from when the user clicks the delete button it deletes the subjects from the list 
this is the code i have Subject_list.php:
// Get all subjects $query = 'SELECT * FROM subjects ORDER BY subjectID'; $statement = $db->prepare($query); $statement->execute(); $subjects = $statement->fetchAll(); $statement->closeCursor(); ?>
Course Manager
Subject List
| Name | |
|---|---|
Add Subject
List Courses
Here is the delete_subject.php code:
// Validate inputs if ($subjectName == null || $subjectName== false) { $error = "Invalid subject ID."; include('error.php'); } else { require_once('database1.php');
// Add the book to the database $query = 'DELETE FROM subjects WHERE subjectID = :subject_id'; $statement = $db->prepare($query); $statement->bindValue(':subject_list', $subjectName); $statement->execute(); $statement->closeCursor();
// Display the subject List page include('subject_list.php'); } ?>
Now on the bottom of the form i need when the user clicks the Add button it adds another subject to the list :
my Add_subject.php code:
// Validate inputs if ($subject == null) { $error = "Invalid category data. Check all fields and try again."; include('error.php'); } else { require_once('database1.php');
// Add the subject to the database $query = "INSERT INTO subjects (subjectName) VALUES (:subject)"; $statement = $db->prepare($query); $statement->bindValue(':subject_list', $subjectName); $statement->execute(); $statement->closeCursor();
// Display the Category List page include('subject_list.php'); } ?>
Database1.php code:
$dsn = 'mysql:host=localhost;dbname=my_courses';
$username = 'mgs_user';
$password = 'pa55word';
try {
$db = new PDO($dsn, $username, $password);
} catch (PDOException $e) {
$error_message = $e->getMessage();
include('database_error.php');
exit();
}
?>
and my_course.sql code:
DROP DATABASE IF EXISTS my_courses;
CREATE DATABASE my_courses;
USE my_courses;
CREATE TABLE subjects(
subjectID Int NOT NULL AUTO_INCREMENT,
subjectName Char(50) NOT NULL,
PRIMARY KEY(subjectID)
);
CREATE TABLE courses(
courseID Int NOT NULL AUTO_INCREMENT,
subjectID Int NOT NULL,
courseName Char(50) NOT NULL,
fee Decimal(10,2) NOT NULL,
PRIMARY KEY(courseID)
);
INSERT INTO subjects (subjectID, subjectName)
VALUES('1', 'Computer Info Systems');
INSERT INTO subjects (subjectID, subjectName)
VALUES('2', 'English');
INSERT INTO subjects (subjectID, subjectName)
VALUES('3', 'American Literature');
INSERT INTO subjects (subjectID, subjectName)
VALUES('4', 'American History');
INSERT INTO subjects (subjectID, subjectName)
VALUES('5', 'Music');
INSERT INTO subjects (subjectID, subjectName)
VALUES('6', 'World History');
INSERT INTO courses (courseID, subjectID, courseName, fee)
VALUES('1', '1', 'Computer Literacy', 500.00);
INSERT INTO courses (courseID, subjectID, courseName, fee)
VALUES('2', '1', 'Java Programming', 550.00);
INSERT INTO courses (courseID, subjectID, courseName, fee)
VALUES('3', '2', 'English 101', 575.00);
INSERT INTO courses (courseID, subjectID, courseName, fee)
VALUES('4', '3', 'American Poets', 525.00);
INSERT INTO courses (courseID, subjectID, courseName, fee)
VALUES('5', '3', 'Autobiographies', 500.00);
INSERT INTO courses (courseID, subjectID, courseName, fee)
VALUES('6', '4', 'American Civil War', 550.00);
INSERT INTO courses (courseID, subjectID, courseName, fee)
VALUES('7', '5', 'Contemporary Music', 500.00);
INSERT INTO courses (courseID, subjectID, courseName, fee)
VALUES('8', '6', 'World War I', 525.00);
INSERT INTO courses (courseID, subjectID, courseName, fee)
VALUES('9', '6', 'World War II', 525.00);
GRANT SELECT, INSERT, DELETE, UPDATE
ON my_courses.*
TO mgs_user@localhost
IDENTIFIED BY 'pa55word';
GRANT SELECT
ON courses
TO mgs_tester@localhost
IDENTIFIED BY 'pa55word';
Course Manager Subject List Name Computer Info Systems Delete English American LiteratureDelete American History Music World History Delete Delete Delete Delete Add Subject Name PHP Add List Courses Course Manager Subject List Name Computer Info Systems Delete English American LiteratureDelete American History Music World History Delete Delete Delete Delete Add Subject Name PHP Add List Courses
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
