PHP Form Error Validation -
I am working on a php form with some validation rules.
If some fields are left empty for which form reports and error messages are required and ask the user to complete the field.
The form currently holds the value of $ _POST data so that if the data field is in the field
I am having a problem with two fields (drop down lists) Populated with data from a database if I complete these fields, but there is an error other than the value in the drop down list, but when I correct the errors and try to submit the form then Y Let me tell you that the drop down list field is empty.
Here is the code for them
Why any thoughts are happening?
For starters, click the & lt; Option value = 0 selected = "selected" & gt; This means that option 0 will always be selected.
You can do something like this, I'm sorry that this snippet has bugs, but you should give it a general idea of what you want:
< Code> & lt ;? Php $ myOptions = array ('0' = & gt; '--- none selected --- ---', '1' = & gt; 'apple', '2' = & gt; 'banana' // ...); ? & Gt; & Lt; Select name = "studentname" & gt; By & lt;? Php foreach ($ myOptions $ key = & gt; $ value) {$ select = isset ($ _ POST ['theOption']) & amp; Amp; $ _POST ['theOption'] == $ key? 'Selected =' selected "':" "; echo" You can do some cleaning using the optional PHP syntax:
This is not part of your bug, but only a good Practice Ideas, some of your HTML tags and their attributes have uppercase, and nowadays it is normal to use loces. This is more standard in this way.
Comments
Post a Comment