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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.