hey guys... i've encountered something which I think may tax ur brains...

what im trying is this:

There is this coaching institute. A person may come here either as a student to enroll for a course, or as a teacher.

Now, if the person has come as a student, we enter into database DB1, the personal details and the course for which he wishes to enroll.(courses are in a drop down menu)

If the person is for a job, we enter into database DB2, the personal details, and the type of job he is here for.(types of jobs are al;so in a drop down menu).

So basically,

1. the user first enters whether he is a student/teacher. He is then redirected to a page asking for his personal details, and course(for student)/position(for teacher).

2. The data in the 2 cases is inserted into different databases.

the PRoblem

Ir-respective of whether the person is a student/teacher, i want to use a common page to ask for his details. This page, will obviously be connected to a different database based on student/teacher. Also, the drop-down menu on the page will depend on teacher/student.


I am unable to implement this...

somebody help me out...

thx...
cheers...

Recommended Answers

All 12 Replies

Create two forms, one for teacher, and one for student. In both, include the following dropdown menu:

<select onchange="MM_jumpMenu('parent',this,0)">
<option value="">Please select student or teacher..</option>
<option value="teacher.php">Teacher</option>
<option value="student.php">Student</option>
</select>

Include this javascript function in the head:

<script type="text/javascript">
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location=\'"+selObj.options[selObj.selectedIndex].value+"\'");
if (restore) selObj.selectedIndex=0;
}
</script>

The function will cause the forms to toggle, depending on which option is selected in the dropdown. There are many ways of doing this, but this seems easiest to me.

hey buddylee17

thx for replying...

i want to stick to HTML/PHP and not se javascript.

Is a solution possible then?

Well, you could have the user come to a common page where they select teacher or student. That page could then direct the user to the appropriate form.

A common conceptual error is the idea that php can interact with the browser after the page has been loaded. PHP alone cannot change anything on the users screen after the page is loaded. It takes javascript to modify the users screen after a page loads. Remember, php runs on the server. JavaScript runs on the browser. They can however interact through a xmlhttprequest (AJAX).

Well, you could have the user come to a common page where they select teacher or student. That page could then direct the user to the appropriate form.

well, thats exactly what i have done....

what i was looking for was a way to make my code more efficient. It does not matter much in this case as there are only 2 options, but in case there are more, is there a better way to use just the one form where the drop-down menu is variabe??

So, let me get this straight. You want one dynamic form which changes based on what the user selects. Is this correct?

yes... but the only thing that changes in the form is the drop down menu.... other fieds remain same for all user inputs...

1. How are you determining whether the user is a student or the teacher ? Do you have a form where the user selects whether he is a student or a teacher ?
2. If you have a dropdown in page1 where the user can select what type of user he is (student or teacher), then you can take respective action in page2 depending upon his choice in page1.

1. How are you determining whether the user is a student or the teacher ? Do you have a form where the user selects whether he is a student or a teacher ?
2. If you have a dropdown in page1 where the user can select what type of user he is (student or teacher), then you can take respective action in page2 depending upon his choice in page1.

1. Yes. the person first encounters a form (say P1) wherein he has to specify whether he is student/teacher.

2. data form this form is collected in the "action" page (say P2) of P1.

3. What i can do is to use an if-else on P2. If(user)-- show menu 1, else show menu2.

The problem i am facing is--- On P2, the data entered(student/teacher) is retreived using PHP ($_POST[""]).... and the form is built in HTML..... so i end up having HTML code inside my PHP script, which "I think" is the actual source of error .... i dont think we are allowed to usee HTML inside a PHP script....

pls clarify....

thx...

The problem i am facing is--- On P2, the data entered(student/teacher) is retreived using PHP ($_POST[""]).... and the form is built in HTML

The form 'belongs' to html. So, it doesn't matter. But, have you, by any chance have .html extension to that script ? In that case, it will not work.
And, you can have html tags inside php.

<?php
echo "<html><body>This is just a test!</body></html>";
?>

Here is a simple example.

<?php
/* This is test.php */
if(isset($_POST['submit'])) {
   $selectedvalue = $_POST['type'];
if($selectedvalue == "teacher") {
echo "Welcome Teacher!";
//do something
} else {
echo "Welcome Student!";
//do something else
}
}
?>
<html>
<body>
<form method="post">
Select an option : <select name="type">
<option value='teacher'>Teacher</option>
<option value='student'>Student</option>
</select><br />
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>

hey nav33n.

you probably did not understand my requirement(or maybe i am not understanding your solution)....

What is need is this:

there is a form, say P1, where the user specifies whether he is a teacher/student.
Irrespective of his answer, he is re-directed to P2 on submission of P1.

Now, P2 is also a form. If the person == teacher, then P2 (also a form) contains some text field, and a drop-down-list, DDL1.

On the other hand, if person == student, then P2 contains the SAME text fields(as in the case of teacher), but a different drop-down-list, say DDL2.

I can do this using 2 different forms, one for the teacher and 1 for the student, but this is inefficient in case i hav more options as there is large amt of data replication.

pls clarify....

thx a lot...

Do a conditional on which drop down to present.

<?php
if($person=="teacher"){?>
<select name="teacher">
<option value="option1t">option1</option>
<option value="option2t">option2</option>
<?php }else{?>
<select name="student">
<option value="option1s">option1</option>
<option value="option2s">option2</option>
<?php }?>
</select>

Umm.. probably, You didn't understand my solution. In my example, I submitted to the same page and echoed the selected option, just to give you an idea how it can be done. Anyway, I hope buddylee17's example is clear enough.

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.