File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes PHP and the fly likes How to save value selected from dropdown list using PHP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Languages » PHP
Bookmark "How to save value selected from dropdown list using PHP" Watch "How to save value selected from dropdown list using PHP" New topic
Author

How to save value selected from dropdown list using PHP

Glories Moh
Greenhorn

Joined: Dec 12, 2010
Posts: 6
I am trying to write a PHP code that display to user groups "the groups are selected from database" and according to the group selected
I want to display the students belong to the selected group. So, I should save the selected value 'which is group name' to be used in selecting student from data base




this block of code is inside html table row

so what I can do to do that?

thanks in advance
Nick Charles
Ranch Hand

Joined: Oct 09, 2011
Posts: 71

Where is your HTML <form> statement? That statement will identify the action (which php file) that will handle the input from the form. The php code will use the select name (Groups) to obtain the value of the selection.
Glories Moh
Greenhorn

Joined: Dec 12, 2010
Posts: 6
Thanks for replying.
I cant send the data to external php file to handle, because I want to make a nother dropdown list for student under this group.
I mean I think the php code of making students dropdown list should be at the same html file. I hope my point is clear.
I appreciate your suggestion.
Thanks again
Nick Charles
Ranch Hand

Joined: Oct 09, 2011
Posts: 71

I never said that the php file had to be external, it must be part of the same app (that is, in the same project/directory structure as the PHP file whose code you posted). You can also post to the same PHP file that displayed the data, but you will have to add code to differneitate between the GET dn POST requests.

But my main point was that you need a <form> statement. And you still haven't indicated if you have one or what it is.
Glories Moh
Greenhorn

Joined: Dec 12, 2010
Posts: 6
Nick Charles wrote:I never said that the php file had to be external, it must be part of the same app (that is, in the same project/directory structure as the PHP file whose code you posted). You can also post to the same PHP file that displayed the data, but you will have to add code to differneitate between the GET dn POST requests.

But my main point was that you need a <form> statement. And you still haven't indicated if you have one or what it is.


Sorry, it seems that I misunderstand you. by the way, I am new to PHP

I added form tag as you see but maybe I don't have idea about using $_POST

Here is my code



I got an error at
Actually I need away to retrive selected value without using submit button.
Thank you so much, I appreciate your help
Nick Charles
Ranch Hand

Joined: Oct 09, 2011
Posts: 71

From the way you have coded the file, it appears that you think that the web page is displayed to the user after line 46 and then line 46 doesn't run until the user enters some input. It does not work that way. Instead, the entire file is processed for a GET (when the user requests the page), and is processed again for a POST (when the user submits the input). You need to read some tutorials on how to handle form input in PHP.

Actually I need away to retrive selected value without using submit button.

Then you need some javascript or AJAX components that will POST the data at the time a selection is made. But you will still need to have a PHP file that will accept the input. My recommendation is to understand how it works with basic form input, with a submit button, and only after you understand that, look into AJAX.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to save value selected from dropdown list using PHP