Jump to content

[SOLVED] html if statement


sdasilva

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/171861-solved-html-if-statement/
Share on other sites

Yeah I agree with mvpetrovich, then you can just change your form to:

 

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

 

By 'html if statement' did you mean JavaScript to update the next select list based upon the first selection?

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:

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.