• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to get selected option with select tag?

 
Ranch Hand
Posts: 391
1
MySQL Database PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 7134
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MySQL Database PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 7134
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MySQL Database PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 7134
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MySQL Database PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your time , i resolved my problem.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for sharing this php code, Its really useful for me..
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic