This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Transfer Learning for Natural Language Processing (MEAP) and have Paul Azunre on-line!
See this thread for details.
Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

How to get selected option with select tag?

 
Ranch Hand
Posts: 391
1
MySQL Database PHP Java
  • 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.
 
Marshal
Posts: 6593
1253
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • 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
MySQL Database PHP Java
  • 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
Marshal
Posts: 6593
1253
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • 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
MySQL Database PHP Java
  • 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
Marshal
Posts: 6593
1253
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • 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
MySQL Database PHP Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your time , i resolved my problem.
 
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..
 
Create symphonies in seed and soil. For this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic