Jump to content

Foreign key problems


Toolmaster

Recommended Posts

Hello everyone, I have a problem with a foreign key in one of my tables, I am creating an online booking system for my university and so far I have created two tables: 1. Lecturer table, 2. Lecturer_Login table

 

This is what I am confused with, below is some coding which i've used to create the two tables:

 

LECTURER TABLE

$sql = 'CREATE TABLE Lecturer( lecturer_id VARCHAR(9) PRIMARY KEY, name Varchar(50) NOT NULL, FOREIGN KEY (office_id)

REFERENCES office (office_id), mob_tel_no INTEGER, email_address Varchar(50))';

 

LECTURER LOGIN TABLE

$sql = 'CREATE TABLE lecturer_Login (login_id VARCHAR(6) PRIMARY KEY,

FOREIGN KEY (username) REFERENCES lecturer(lecturer_id), passwrd VARCHAR(15) NOT NULL)';

 

The foreign key "username" is not shown when I query for the description of the table, I don't know why and what I can do about it.  ??? ???

 

Any ideas?

Link to comment
Share on other sites

What I have done is just create the tables, no data has been inserted in the tables as of yet.

Now, when I go onto a front end interface of mysql and I type "DESC lecturer_login"

 

there are only two attributes visible, one is the login_id (pk) and the other is the password attribute. The foreign key named username, which references from the lecturer table "lecturer_id" does not appear.  ???

Link to comment
Share on other sites

What I want is when I insert a value in the foreign key attribute (username) within the lecturer_login table, it will look at the lecturer table to see if the lecturer_id inserted in the foreign key attribute is existing. If it is existing  then users will be signed in providing their password is correct, if not then they will obviously recieve notification of their login being unsuccessful.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.