perhaps someone can help me with an example I've come up with to help me to better understand how to build a relationship in Mysql.
I want to create two tables, "websites" and "category" for example.
I would have the fields as follows:
websites:
web_id
web_address
cat_id
category:
cat_id
cat_name
My goal is to have a webfront in which to input the new data. SO, I would have a webform that asks for the web address, and then a drop down menu that is populated through a self populating script ....
Example:
web address😐_____________|
Category: >computing
>sports
>php
etc.
This form would then go to the php script which would use an insert statement to input the new information.
Now I have two questions:
1) How would or SHOULD I go abouts creating the database relationship?
and
2) How do I create the insert statement?
My attempt for the creation of the relationship is this:
the websites table:
CREATE TABLE 'websites' ('web_id' INT NOT NULL AUTO_INCREMENT PRIMARY KEY, 'web_address' TEXT NOT NULL, 'cat_id' INT NOT NULL,UNIQUE ('web_id', 'web_address'), FOREIGN KEY (cat_id) REFERENCES category (cat_id) ON DELETE CASCADE);
and then the category table:
CREATE TABLE 'category' ('cat_id' INT NOT NULL AUTO_INCREMENT PRIMARY KEY, 'cat_name' VARCHAR(20) NOT NULL, UNIQUE ('cat_id', 'cat_name'));
....... Now, I'm not sure if I've done that correctly as it has been somewhat difficult to find info regarding relational db syntax in mysql for me.
Then there is the question regarding the SQL statement in the php page that will input the info into the db from the webform.However, I'm not sure about the part where i want the category name that was selected to refer to the "cat_id" instead of the actual name in the "cat_name" field.
I have this ... question mark being the portion I'm stuck on.
INSERT into websites (web_id, web_address, cat_id) VALUES (Null, '$web_address', '???????');
Thanks for ANY help.