sdasilva Posted August 25, 2009 Share Posted August 25, 2009 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 More sharing options...
mvpetrovich Posted August 26, 2009 Share Posted August 26, 2009 Your table layouts may not be what you want. Consider: student (studentNum, firstName, lastName) course(courseId, courseName, courseTotalCapacity) course_allocation(studentNum, courseID) Then you just need the studentID and courseID. Link to comment https://forums.phpfreaks.com/topic/171861-solved-html-if-statement/#findComment-906537 Share on other sites More sharing options...
Adam Posted August 26, 2009 Share Posted August 26, 2009 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? Link to comment https://forums.phpfreaks.com/topic/171861-solved-html-if-statement/#findComment-906540 Share on other sites More sharing options...
sdasilva Posted August 26, 2009 Author Share Posted August 26, 2009 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. Link to comment https://forums.phpfreaks.com/topic/171861-solved-html-if-statement/#findComment-906954 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.