Search⌘ K
AI Features

Submitting Form Data as Query Parameters

Understand how to use HTML forms to submit data as query parameters in PHP. Learn to create user-friendly forms that display submitted values and handle unset query parameters properly to avoid errors.

Why use HTML forms?

We have seen how you can let the PHP server serve PHP scripts. We also saw how you can provide input to these scripts using query parameters, which are part of the URL. This works great if the input is something the application produces, like the random number in /random.php. But if we want the user to provide the input themselves, we should use an HTML form. A form is much more user-friendly since the user doesn’t have to modify the URL manually. They can just type something in a form field, select an item from a combobox, put a checkmark somewhere, and submit the data to the server.

Adding a form

We’re going to add a simple form to the /kittens.php page. The form has a field for ...