Question: running into errors in trying to get this php form from when the user clicks the delete button it deletes the subjects from the list
running into errors in trying to get this php form from when the user clicks the delete button it deletes the subjects from the list
when i hit the delete button it goes to Invalid subject ID. page . and when i try to add something to a list it shows Invalid category data. Check all fields and try again.i feel like i almost have it i just need an extra eye on it .

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();
}
?>
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
