interesting situation

Reply

Join Date: Jun 2008
Posts: 46
Reputation: akshit is an unknown quantity at this point 
Solved Threads: 0
akshit akshit is offline Offline
Light Poster

interesting situation

 
0
  #1
Jul 3rd, 2008
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...
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 596
Reputation: buddylee17 has a spectacular aura about buddylee17 has a spectacular aura about 
Solved Threads: 125
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Pro

Re: interesting situation

 
0
  #2
Jul 3rd, 2008
Create two forms, one for teacher, and one for student. In both, include the following dropdown menu:
  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:
  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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 46
Reputation: akshit is an unknown quantity at this point 
Solved Threads: 0
akshit akshit is offline Offline
Light Poster

Re: interesting situation

 
0
  #3
Jul 3rd, 2008
hey buddylee17

thx for replying...

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

Is a solution possible then?
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 596
Reputation: buddylee17 has a spectacular aura about buddylee17 has a spectacular aura about 
Solved Threads: 125
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Pro

Re: interesting situation

 
0
  #4
Jul 3rd, 2008
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).
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 46
Reputation: akshit is an unknown quantity at this point 
Solved Threads: 0
akshit akshit is offline Offline
Light Poster

Re: interesting situation

 
0
  #5
Jul 3rd, 2008
Originally Posted by buddylee17 View Post
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??
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 596
Reputation: buddylee17 has a spectacular aura about buddylee17 has a spectacular aura about 
Solved Threads: 125
buddylee17's Avatar
buddylee17 buddylee17 is offline Offline
Posting Pro

Re: interesting situation

 
0
  #6
Jul 3rd, 2008
So, let me get this straight. You want one dynamic form which changes based on what the user selects. Is this correct?
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 46
Reputation: akshit is an unknown quantity at this point 
Solved Threads: 0
akshit akshit is offline Offline
Light Poster

Re: interesting situation

 
0
  #7
Jul 3rd, 2008
yes... but the only thing that changes in the form is the drop down menu.... other fieds remain same for all user inputs...
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: interesting situation

 
0
  #8
Jul 3rd, 2008
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.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 46
Reputation: akshit is an unknown quantity at this point 
Solved Threads: 0
akshit akshit is offline Offline
Light Poster

Re: interesting situation

 
0
  #9
Jul 9th, 2008
Originally Posted by nav33n View Post
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...
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: interesting situation

 
0
  #10
Jul 9th, 2008
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.
  1. <?php
  2. echo "<html><body>This is just a test!</body></html>";
  3. ?>
Here is a simple example.
  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>
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC