On delete Cascade in php

  • ## ON Delete Cascade:
Cascade will work when you delete something on table Courses. Any record on table BookCourses that has reference to table Courses will also be deleted.
But when you try to delete on table BookCourses only the table itself is affected and not on the Courses
follow-up question: why do you have CourseID on table Category?
Maybe you should restructure your schema into this,
CREATE TABLE Categories
(
  Code CHAR(4) NOT NULL PRIMARY KEY,
  CategoryName VARCHAR(63) NOT NULL UNIQUE
);
CREATE TABLE Courses
(
  CourseID INT NOT NULL PRIMARY KEY,
  BookID INT NOT NULL,
  CatCode CHAR(4) NOT NULL,
  CourseNum CHAR(3) NOT NULL,
  CourseSec CHAR(1) NOT NULL,
);
ALTER TABLE Courses
ADD FOREIGN KEY (CatCode)
REFERENCES Categories(Code)
ON DELETE CASCADE;
Please follow and like us:
0

Get email not send errors

How can I get the error message for the mail() function?

You can use error_get_last()when mail() returns false.

$success = mail(‘example@example.com’, ‘My Subject’, $message);
if (!$success) {
$errorMessage = error_get_last()[‘message’];
}
With print_r(error_get_last()), you get something like this:

[type] => 2
[message] => mail(): Failed to connect to mailserver at “x.x.x.x” port 25, verify your “SMTP” and “smtp_port” setting in php.ini or use ini_set()
[file] => C:\www\X\X.php
[line] => 2

Please follow and like us:
0