I have created two table by generating via forms. My question is although second table's foreign key appears on phpmyadmin it doesnt have that same value with the first table's primary key.
currently foreign key has all zero values in all of the rows.
Table codes:

$sql2='CREATE TABLE IF NOT EXISTS CourseList(
Course_id  int NOT NULL auto_increment,
CourseCode varchar(10) NULL,
CourseName varchar(40) NULL,
Instructor varchar(40) NULL,
PRIMARY KEY(Course_id)
)';

$sql3='CREATE TABLE IF NOT EXISTS StudentAccess(              
StudentNumber varchar(12) NOT NULL,
StudentFirstName varchar(15) NOT NULL,
Course_id int NOT NULL,
FOREIGN KEY (Course_id) REFERENCES CourseList(Course_id) ON DELETE CASCADE
)';

how should i write foreign key code to link "StudentAccess's Course_id" to "CourseList's Course_id"??

Recommended Answers

All 2 Replies

i still can't make it. :(
somehow FOREIGN KEY (Course_id) REFERENCES CourseList(Course_id) ON DELETE CASCADE doesn't work.

it also work but StudentAccess table's Course_id is all zeros.
i also tried Course_id int NOT NULL REFERENCES CourseList(Course_id) but it doesn't work too.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.