Off late I’ve had the need to use select tags in html to upload user information into the database. However I cannot get this done because I do not know what is happening.
That’s what that code does. When you hit the ‘submit’ button, the current selection in your “property-type” field is passed through to the php code as $_POST[‘property-type’], so you should see that value going into your table.
What is happening that caused you to ask the question?
Note that the “name” parameter in each of your option tags has no effect - the “value” parameter contains the value passed into the $_POST array. The name is taken from the select tag that surrounds the various options.
Be sure to add the action and method attributes to your form tag. If the method is not specified, the form will send info with GET through the url… In most cases, POST is a better option.
The action will direct form to the specified page. When empty, form is pointing to same page as the form or add a page name, e.g. processing.php to direct to that page.
Forms pass the values of the input, textarea and select fields that have a NAME to the server. They do not pass anything to the server by ID and since the option tags are a there simply to supply the allowed values and text for the select they don’t have a name attribute.
The FOR attribute on a label attaches the label to the form field with the corresponding ID.
In PHP submitting the form loads either the $_GET array or the $_POST array depending on whether the form tag has method=“POST” or not.
PHP unlike other server side languages does not load multiple fields with the same NAME as an array, instead it overwrites them so hat only the lst one in the form for each name gets passed.
Yes, the entire code has been posted and was working ok before I decided to add the new select tags. Now it doesn’t work and I get the error SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
Disregarding the invalid HTML that is likely to cause trouble once you get past this. “number” appears 6 times in your code example.
$number = $pdo->query("SELECT id from properties order by id desc limit 1");
$number = $number -> fetch (PDO::FETCH_OBJ);
$number = $number->id;
header ("Location: single-edit.php?id=$number");
Thanks for your response. I deleted that block of code entirely but I still get the error. Moreover, the code prior to that $number bit doesn’t function like it should.
Disregarding the invalid HTML
Are you referring to me not using the ul tags? I didn’t think leaving them out would be a html problem. Or are you referring to something else?
Any way, just to be clear, the code you posted is the single-edit.php file?
And when you pasted the view-source mark-up into http://validator.w3.org/ it didn’t give you any errors?
The reason I mention having valid mark-up is because if it isn’t valid you can’t rely on it working as you hope it to. It might, but it might not.
Oh no. This is member.php and when the insert completes, I get the last id and open that in the single-edit.php so the uploader can then add an image gallery for that property id.
Thank you all for your inputs. I rewrote and reorganised the whole page because it had gotten quit messy after addition upon addition of code and now it is working.