File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to save value selected from dropdown list using PHP

 
Glories Moh
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 71
Linux PHP Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 71
Linux PHP Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 71
Linux PHP Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic