Jump to content

Form function help <select="selected"> from SQL DB


colombian

Recommended Posts

My basic problem, is that I cannot get the form to keep the values if there is an error on submission.

My forms with local arrays work fine, and basically go like this:

function time_hour($hour) {
$hours = range(1,12);
global $hour; //the form element name
foreach ($hours as $h) {
     if $h == $hour) { $selected = "select='selected'";}
     else { $selected = ""; }
     
     echo "<option value ='{$h}' {$selected}>{$h}</option>";
}

I don't have the code with me, but that is overall how it goes, and it works just fine. However, when I am trying it with values with the MySQL database, I just can't figure out how to get it to work.

 

I can get the values fine, and display them fine, I just can't get the select to change appropriately after submission.

 

Any help would be greatly appreciated. And I apologize for not having the specific non working code here with me, it's at work. But basically I query the database, and try to use a foreach $row as $value command and use something similar to the sample above, but it just refuses to keep those values.

 

Thanks in advance.

I have been working on this for a while without luck, and it should* be easy =/

 

Any links with good PHP form function could also help.

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/98531-form-function-help-from-sql-db/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.