943,552 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1200
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Jul 3rd, 2008
0

interesting situation

Expand Post »
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...
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
akshit is offline Offline
46 posts
since Jun 2008
Jul 3rd, 2008
0

Re: interesting situation

Create two forms, one for teacher, and one for student. In both, include the following dropdown menu:
html Syntax (Toggle Plain Text)
  1. <select onchange="MM_jumpMenu('parent',this,0)">
  2. <option value="">Please select student or teacher..</option>
  3. <option value="teacher.php">Teacher</option>
  4. <option value="student.php">Student</option>
  5. </select>
Include this javascript function in the head:
javascript Syntax (Toggle Plain Text)
  1. <script type="text/javascript">
  2. function MM_jumpMenu(targ,selObj,restore){ //v3.0
  3. eval(targ+".location=\'"+selObj.options[selObj.selectedIndex].value+"\'");
  4. if (restore) selObj.selectedIndex=0;
  5. }
  6. </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.
Reputation Points: 232
Solved Threads: 137
Practically a Master Poster
buddylee17 is offline Offline
665 posts
since Nov 2007
Jul 3rd, 2008
0

Re: interesting situation

hey buddylee17

thx for replying...

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

Is a solution possible then?
Reputation Points: 10
Solved Threads: 0
Light Poster
akshit is offline Offline
46 posts
since Jun 2008
Jul 3rd, 2008
0

Re: interesting situation

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).
Reputation Points: 232
Solved Threads: 137
Practically a Master Poster
buddylee17 is offline Offline
665 posts
since Nov 2007
Jul 3rd, 2008
0

Re: interesting situation

Click to Expand / Collapse  Quote originally posted by buddylee17 ...
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??
Reputation Points: 10
Solved Threads: 0
Light Poster
akshit is offline Offline
46 posts
since Jun 2008
Jul 3rd, 2008
0

Re: interesting situation

So, let me get this straight. You want one dynamic form which changes based on what the user selects. Is this correct?
Reputation Points: 232
Solved Threads: 137
Practically a Master Poster
buddylee17 is offline Offline
665 posts
since Nov 2007
Jul 3rd, 2008
0

Re: interesting situation

yes... but the only thing that changes in the form is the drop down menu.... other fieds remain same for all user inputs...
Reputation Points: 10
Solved Threads: 0
Light Poster
akshit is offline Offline
46 posts
since Jun 2008
Jul 3rd, 2008
0

Re: interesting situation

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.
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Jul 9th, 2008
0

Re: interesting situation

Click to Expand / Collapse  Quote originally posted by nav33n ...
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...
Reputation Points: 10
Solved Threads: 0
Light Poster
akshit is offline Offline
46 posts
since Jun 2008
Jul 9th, 2008
0

Re: interesting situation

Quote ...
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 Syntax (Toggle Plain Text)
  1. <?php
  2. echo "<html><body>This is just a test!</body></html>";
  3. ?>
Here is a simple example.
php Syntax (Toggle Plain Text)
  1. <?php
  2. /* This is test.php */
  3. if(isset($_POST['submit'])) {
  4. $selectedvalue = $_POST['type'];
  5. if($selectedvalue == "teacher") {
  6. echo "Welcome Teacher!";
  7. //do something
  8. } else {
  9. echo "Welcome Student!";
  10. //do something else
  11. }
  12. }
  13. ?>
  14. <html>
  15. <body>
  16. <form method="post">
  17. Select an option : <select name="type">
  18. <option value='teacher'>Teacher</option>
  19. <option value='student'>Student</option>
  20. </select><br />
  21. <input type="submit" name="submit" value="submit">
  22. </form>
  23. </body>
  24. </html>
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Help, Dynamic Subject for mail script
Next Thread in PHP Forum Timeline: Array echoing problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC