• Home
  • PHP
  • MySQL
  • Laravel
  • Demos
  • HTML
  • jQuery
  • Framework
  • Request Tutorial
PHP Lift
  • Home
  • Demos
  • Advertisement
PHP Lift
  • Home
  • PHP
  • MySQL
  • Laravel
  • Demos
  • HTML
  • jQuery
  • Framework
  • Request Tutorial
  • Follow
    • Facebook
    • Twitter
    • Google+
    • Pinterest
    • Youtube
    • Instagram
    • RSS
Passing input parameters in PHP
Home
PHP

Passing input parameters in PHP

September 15th, 2025 Ivan Dimov PHP 0 comments

Facebook Twitter Google+ LinkedIn Pinterest

In this brief article, we will see how to work with forms and inputs in PHP.

Using HTML forms, you can pass parameters to the PHP back-end. Let us examine the following form:

<form action=’’>



<input type=’text’ name=’name’>



<input type=’submit’ name=’submit’ value=’Submit’>



</form>

Now, this form will perform a GET submission. In PHP, you can get the text input with the following code:

If (array_key_exists(“name”, $_GET)) {



// do something with $_GET[‘name’]

}

Should the form be using a POST request method

<form method=’post’ action=’’>



<input type=’text’ name=’name’>



<input type=’submit’ name=’submit’ value=’Submit’>



</form>

Now, the difference is that the form above uses POST for submission. A major difference between GET and POST is that GET submits the parameters as part of the URL. The previous submission would have looked like this with GET: page.com?name=someName&submit=Submit. An obvious drawback with such submission is that it would stay within the browser’s history, it can be bookmarked and shared which is totally not a good idea when the data ought not to be shared. Therefore, for data which is not meant to be shared publicly and data that is private or sensitive always use POST.

In PHP, you can get the name input from a POST submission by using the $_POST superglobal instead of $_GET:

If (array_key_exists(“name”, $_POST)) {



// do something with $_POST[‘name’]

}

It is also possible to expect both POST and GET submissions with the same inputs; or allow both for an API, etc. In such a case, you can simply check the $_REQUEST superglobal for the desired input, and if the input exists from a POST or a GET submission, it will be available in the $_REQUEST superglobal.

If (array_key_exists(“name”, $_REQUEST)) {



// do something with $_REQUEST[‘name’]

}

There are also PUT and DELETE request methods with the HTTP protocol but they are not typically used with forms yet. You may still rely on it when using APIs though. DELETE is used when you want to delete some form of a record and PUT is used when you want to put some file or a record at a specific URL.

Finally, the form could submit to any/arbitrary URL, where you could check the $_GET, $_POST, or $_REQUEST superglobals for inputs.

<form action=’myscript.php’>



<input type=’text’ name=’name’>



<input type=’submit’ name=’submit’ value=’Submit’>



</form>

In the case above, we should have a file called myscript.php in which we check for the inputs.

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook

Related

  • Tags
  • PHP
Facebook Twitter Google+ LinkedIn Pinterest
Next article Free PHP, HTML, CSS, JavaScript/TypeScript editor - CodeLobster IDE
Previous article Working with APIs in PHP

Ivan Dimov

Ivan is a student of IT, a freelance web designer/developer and a tech writer. He deals with both front-end and back-end stuff. Whenever he is not in front of an Internet-enabled device he is probably reading a book or traveling. You can find more about him at: http://www.dimoff.biz. facebook, twitter

Related Posts

Is PHP dead in 2021? Is PHP still relevant or worth the effort? PHP
September 17th, 2025

Is PHP dead in 2021? Is PHP still relevant or worth the effort?

What is the future of PHP in 2023 PHP
September 17th, 2025

What is the future of PHP in 2023

How to Create PDFs from HTML with PHP and Dompdf HTML
September 17th, 2025

How to Create PDFs from HTML with PHP and Dompdf

Leave a Reply Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe
Get new posts by email:
Powered by follow.it
Advertisement
Like us
Recent Posts
  • Is PHP dead in 2021? Is PHP still relevant or worth the effort?
  • JavaScript tips and tricks, Part 2
  • What is the future of PHP in 2023
  • How to Create PDFs from HTML with PHP and Dompdf
  • PHP Basics
Categories
  • API
  • Bootstrap
  • Bot
  • CSS
  • CSS 3
  • Database
  • Designing
  • Framework
  • Guide
  • HTML
  • HTML 5
  • JavaScript
  • jQuery
  • Laravel
  • MySQL
  • Node.js
  • oAuth
  • Payment
  • PHP
  • Python
  • Social
  • Tips
  • Web 3.0
  • WordPress
Weekly Tags
  • PHP
  • javascript
  • How to
  • laravel
  • css
  • HTML to PDF
  • jQuery
  • api
  • Web Development
  • MYSQL
  • About
  • Privacy Policy
  • Back to top
© PHPLift.net. All rights reserved.