Hi there,
I have 3 tables:
Student (studentNum,firstName,lastName,CourseName),
course (courseID,courseTotalCapacity),
course_allocation (studentNum,courseID).
I have 3 courses, MATHS=101,BIOLOGY=102,CHEMISTRY=103.
My form has the following:

<SELECT NAME="CourseName">
<OPTION VALUE="MATHS">MATHS</OPTION>
<OPTION VALUE="BIOLOGY">BIOLOGY</OPTION>
<OPTION VALUE="CHEMISTRY">CHEMISTRY</OPTION>
</SELECT></td></tr>

<SELECT NAME="courseID">
<OPTION VALUE="101">MATHS=101</OPTION>
<OPTION VALUE="102">BIOLOGY=102</OPTION>
<OPTION VALUE="103">CHEMISTRY=103</OPTION>
</SELECT>

I would like to have some kind of a if statement, that if the user chooses the CourseName MATHS, then the courseID 101 is entered to the course and course_allocation tables and MATHS entered to the CourseName table.
As it is the user has to choose MATHS and choose MATHS=101, then click submit.
Any help, please.

What is the problem ? You would be selecting CourseName and courseID. So, when you post the form, You will have "MATHS" in $_POST and "101" in $_POST. Then it is all about the insert query.
Or am I missing something ? :-/

trtcom1,

I think it's simple - to select a course, you need just one select menu, not two.

<SELECT NAME="course">
<OPTION VALUE="101">MATHS</OPTION>
<OPTION VALUE="102">BIOLOGY</OPTION>
<OPTION VALUE="103">CHEMISTRY</OPTION>
</SELECT>

All the intelligence that marries up the courseIds with courseNames should reside server-side. Hence the user knows courses by name (because that's what is presented to him/her) whilst the server-side script (the php that is requested when the form is submitted) knows the courses by id (which will typically be a primary key in a database record).

Airshow

the student table does not need the text course names
the reporting logic can print the text names if necessary from the course table

student (studentNum,firstName,lastName,),
course (courseID, CourseName,courseTotalCapacity),
course_allocation (studentNum,courseID)

one link between each datatable

Thank you very much for your comments and help. This thread can be considered as solved. This is my final solution:
Here the html select:

<SELECT NAME="courseID">
<OPTION VALUE="101">MATHS</OPTION>
<OPTION VALUE="102">BIOLOGY</OPTION>
<OPTION VALUE="103">CHEMISTRY</OPTION>
</SELECT>

And created a php if-statement for it:

if ($courseID =='101')
{
      $CourseName == 'MATHS';
      //code for the insert statement
}

if ($courseID =='102')
{
      $CourseName = 'BIOLOGY';
      //code for the insert statement
}

And it is working fine.
But the same does not work for the update statement.

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.