• 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 save value selected from dropdown list using PHP

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 71
PHP Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
PHP Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
PHP Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic