Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get selected option with select tag?

 
Mahtab Alam
Ranch Hand
Posts: 391
1
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have three options depending on , i want to redirect the user on three diferrent pages like
php1.php
php2.php
php3.php

<select>
<option value="admin">Administrator</option>
<option value="perm">Permanent</option>
<option value="guest">Guest</option>
</select>

How to do that.
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4435
256
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Client side:
1. How do you send the selected value to the server? Is there <form> tag or your Javascript does it?
2. How do you identify the name of the parameter? Does your <select> tag has a 'name' attribute or your Javsascript does it?

Server side:
3. Did you try reading the selected value via $_POST?
4. If you did the step 3, did you try using if conditions or switch conditions to check the selected value?
5. If you did all these steps, what all you need is to set a header "Location" header to the redirect path as in header('Location: php1.php');
 
Mahtab Alam
Ranch Hand
Posts: 391
1
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all , i will like to say thank because of your Exam lab i scored 93% in OCJP6 exam.




and the tour.php file


it gives notice undefined constant 'Ajeet'
notice undefined constant 'Mehtab'
notice undefined constant 'Manish'
notice undefined constant 'jitu'
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4435
256
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad that ExamLab helped

About the question, are you sure that you have used quotes to denote all String literals as in 'Ajeet' and you still get this notice? You get that notice when quotes are not used.

Another thing I noticed is you omitted the 'value' attribute from your <option> tags, so no value will be assigned to your 'hero' parameter (this is where isset is usefil). I can't however understand how you get an undefined constant warning even with that.
 
Mahtab Alam
Ranch Hand
Posts: 391
1
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to insert the selected option in the database , how can i do that.

How to get the selected value and make a query to insert in the table in database.
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4435
256
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mahtab Alam wrote:How to get the selected value and make a query to insert in the table in database.

Did you manage to obtain the parameter value anyway? If not, show us your code. We can discuss it over here as that's what this topic is all about. If your question is about setting up database connections, or persisting data over a connection, please start a new topic in this form. When you do that, please IsolateTheProblem - you got the param value already, so the question should probably be only on persisting a value to the database.
 
Mahtab Alam
Ranch Hand
Posts: 391
1
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your time , i resolved my problem.
 
nancy jack
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for sharing this php code, Its really useful for me..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic