POST Request Method in PHP with Source Code

POST Request Method in PHP with Source Code mytechlearns
PHPLeave a Comment on POST Request Method in PHP with Source Code

POST Request Method in PHP with Source Code

POST Request Method in PHP with Source Code

In software development using php, POST Method is very popular name and easily to use and handle data. When we pass data from one page to another page we can use POST method. In this way, user also show all the data which passing in the POST method. It does not show user browser. But this is very much secure way to passing data from onek page to another page. Because of this developer prefer it use most of the time. Let’s show how can pass data using get method:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Form Data Save Using PHP POST Method Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  <h2 class="text-center">Bootstrap Form Data Save Using PHP POST Method</h2>
  <form class="form-horizontal" id="" name="" action="show.php" method="POST">

    <div class="form-group">
      <label class="control-label col-sm-2" for="name">Full Name:</label>
      <div class="col-sm-10">
        <input type="name" class="form-control" id="name" placeholder="Enter Your Name" name="name">
      </div>
    </div>

    <div class="form-group">
      <label class="control-label col-sm-2" for="phone">Phone:</label>
      <div class="col-sm-10">
        <input type="phone" class="form-control" id="phone" placeholder="Enter Phone Number" name="phone">
      </div>
    </div>

    <div class="form-group">
      <label class="control-label col-sm-2" for="dept">Department:</label>
      <div class="col-sm-10">
        <select type="text" id="dept" class="form-control" name="dept"> 
        	<option selected value="">Select Your Department</option> 
            <option value="mytechlearns.com">My Tech Learns</option> 
            <option value="BBA">BBA</option> 
            <option value="CSE">CSE</option> 
            <option value="EEE">EEE</option> 
        </select>
      </div>
    </div>

    <div class="form-group">        
      <div class="col-sm-offset-2 col-sm-10">
        <button type="submit" value="submit" id="submit" class="btn btn-default">Submit</button>
      </div>
    </div>
  </form>
</div>

</body>
</html>

In this page, when user submit button press then all the name tag value pass the another page show.php. Have a look this page:

<html>
<head>
	<title>PHP POST data receive and show</title>
</head>
<body>
	<?php 
		$name = $_POST['name'];
		$phone = $_POST['phone'];
		$dept = $_POST['dept'];
	?>

	<h2>Full Name: <?php echo $name; ?></h2>
	<h3>Phone Number: <?php echo $phone; ?></h3>
	<h3>Department: <?php echo $dept; ?></h3>
</body>
</html>

Get all the value in this page and echo using to show all this value.

That’s all for today. Happy Coding….

Source Code: Click Here

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top