PHP Form with lookup table dropdown list

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
texmansru47
Forum Commoner
Posts: 42
Joined: Mon May 12, 2008 11:27 am

PHP Form with lookup table dropdown list

Post by texmansru47 »

Does anyone know where I can find a good reference of how to incorporate a dropdown list (from a lookup table in my MySQL Database) along with User input data?

Thanks,

Texman
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: PHP Form with lookup table dropdown list

Post by califdon »

texmansru47 wrote:Does anyone know where I can find a good reference of how to incorporate a dropdown list (from a lookup table in my MySQL Database) along with User input data?
First you need to understand the HTML for a dropdown box in a form. If you need help with this, try: http://w3schools.com/html/tryit.asp?fil ... ml_select2.
Then, of course, you need to know the PHP syntax used to connect to a MySQL database and extract the data to be used in a while loop for all the <option...>...</option> lines. For this, you might find http://w3schools.com/php/php_mysql_intro.asp useful.
texmansru47
Forum Commoner
Posts: 42
Joined: Mon May 12, 2008 11:27 am

Re: PHP Form with lookup table dropdown list

Post by texmansru47 »

Thank you for the information, but the second is not really what I need. But there are some great tips there. What I need to find is a reference that could help me decypher the following:

When the user selects the option from the Drop Down List, this creates a variable that will be used to process an Insert from the lookup table into the required table (i.e. to eliminate some human error with excessive typing). What I cannot find is how to (if this is even possible) to take the variable from the selection and use it to pull the correct data from teh lookup table.

I think I need to take that variable and process a query on that lookup table and take the results and insert them into the correct table. Sounds right, but may not be.

Secondly, I need this process to occur without leaving the initial HTML form, and where when the selection is processed the fields in questions are populated with something like a screen refresh, and the user then can complete the other fields data insertion.

These two steps are what I cannot find... I was hoping that a simple reference from Drop Down lists would surfice, but I guess I was wrong... still not sure.

Thanks,

Texman
nowaydown1
Forum Contributor
Posts: 169
Joined: Sun Apr 27, 2008 1:22 am

Re: PHP Form with lookup table dropdown list

Post by nowaydown1 »

There isn't really a simple short example that I could give you to demonstrate what you're trying to accomplish. Ultimately, for the goals you outlined, what you need to be looking at is 'ajax'. You should take a look at this:

http://www.w3schools.com/PHP/php_ajax_database.asp

You would just be adding additional steps to the PHP script that processes your ajax request to do whatever table insertion stuff you need. Hope that helps.
texmansru47
Forum Commoner
Posts: 42
Joined: Mon May 12, 2008 11:27 am

Re: PHP Form with lookup table dropdown list

Post by texmansru47 »

It is closer so thank you for the lead... the problem is, there is where I show my ignorance... I cannot seem to understand how to get that selected data into the appropriate table (same database). It is the simple things that I cannot grasp I guess.

I ran the example they had, but I could not tell whether it worked or did not... fun.

Thanks,

Texman
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: PHP Form with lookup table dropdown list

Post by califdon »

The problem is that you are asking, in effect, "how do I do step 738 of a 10,000 step process?" Well, I'm exaggerating, of course, but you see my point, I hope. This is something we all do for nearly every project we undertake, but the exact code to do it depends on the rest of the project. If you are interested in learning HTML, CSS, Javascript, PHP and Ajax, you can get a lot of help from the w3schools.com website and other places, including forums like this one. But you can't really expect to ask how to do one tiny piece of a larger project without knowing how to do the rest of it.
Post Reply