Having a form as below, what should I do to my database or how should I structure my database so that for instance, a particular user will have all the three entries attached to him:
**********************************************************

<html>
<form action="processForm2.php" method="post">
        <p>First Entry</p>
        <div id="original">
        <select name="subject[]">
        <option>English</option>
        <option>Mathematics</option>
        <option>Physics</option>
        <option>Chemistry</option>
        <option>Biology</option>
        </select>
        <select name="grade[]">
        <option>A</option>
        <option>B</option>
        <option>C</option>
        </select>
        <select name="year[]">
        <option>2012</option>
        <option>2011</option>
        <option>2010</option>
        </select>
        </div>
        <p>Second Entry</p>
        <div id="original">
        <select name="subject[]">
        <option>English</option>
        <option>Mathematics</option>
        <option>Physics</option>
        <option>Chemistry</option>
        <option>Biology</option>
        </select>
        <select name="grade[]">
        <option>A</option>
        <option>B</option>
        <option>C</option>
        </select>
        <select name="year[]">
        <option>2012</option>
        <option>2011</option>
        <option>2010</option>
        </select>
        </div>
        <p>Third Entry</p>
        <div id="original">
        <select name="subject[]">
        <option>English</option>
        <option>Mathematics</option>
        <option>Physics</option>
        <option>Chemistry</option>
        <option>Biology</option>
        </select>
        <select name="grade[]">
        <option>A</option>
        <option>B</option>
        <option>C</option>
        </select>
        <select name="year[]">
        <option>2012</option>
        <option>2011</option>
        <option>2010</option>
        </select>
        </div>
    </form>
    </html>

*************************

To submit my data to the database in mysql, I tried using a table "course" in a database with the respective numbers of Columns "email"(Primary key), "subject", "grade", "year". It complained of duplicate entries (Primary key). But when I changed the structure of the "course" table to "Id_no"(Primary key), "subject", "grade", "year", the data was submitted. But herein lies the big question? How do I associate the three entries to that one particular user using his email or his user ID???
PLEASE YOUR HELP WILL BE APPRECIATED!

Recommended Answers

All 3 Replies

Your case can be solved by using composite key (2 or more column together makes primary key of table)
You can make (email_id, subject, year) as primary key

If You already having single column primary key "id_no", so in that case make unique key of (email_id, subject, year)

So what you are saying is about me using a three primary key structure?
Well, what about me using something like this below:

Login_table: {"email_id", "Password"}.
Courses_table: {"Subject_id","grade", "year", "email_id"}.
Subject_id: {"Subject_id", "Subject"}.

yes, you are right

For courses table

Case 1 (if one person is going to learn subject only once in life time)
keep 2 cols (subject_id, email_id) as primary key

Case 2 (if one person is going to learn same subject again next year due failure)
keep 3 cols (subject_id, year, email_id) as primary key

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.