Skip to content

CodeMahal

Menu
  • Home
  • Tutorials
    • Web design
      • HTML & CSS
      • JavaScript
      • PHP
    • Coding
      • HTML & CSS
      • JavaScript
      • C#
      • Xamarin and C#
      • Python
      • Arduino
      • PHP
    • Mobile app development
      • Xamarin and C#
    • Game design
      • Unity 2D and 3D Game Development
      • PlayCanvas
      • WoofJS
    • 3D Modelling & Animation
      • Maya 3D
    • Adobe design software
      • Adobe Illustrator
      • Adobe Photoshop
      • Adobe Flash
      • Adobe InDesign
      • Adobe Premiere
    • CAD (Computer Aided Design)
      • Onshape CAD Tutorials
    • Robotics
      • Arduino
    • More…
  • About
  • YouTube
  • Twitter

Request method and handling form data in one file (PHP)

Posted on March 6, 2016April 14, 2017 by Daniel Wood

This tutorial explains how to handle submitted form data in one file with PHP and also how to work with the request method in PHP.

The request method can be checked to see if data has been submitted using the GET or POST method. For example, if the POST method was used, then a PHP program can then collect data using the POST method.

Watch the video below and then scroll down to see the sample code.

http://codemahal.com/wp-content/uploads/2016/03/Request-method-and-handling-form-data-in-one-file.mp4

Sample PHP code:

<?php
  if($_SERVER['REQUEST_METHOD'] !='POST'){
    echo'
      <form action="" method="POST">
      <p>Enter your name:</p>
      <p>Name: <input type="text" name="name"></p>
      <p><input type="submit"></p>
      </form>
    ';
  }
  else{
    if(!empty($_POST['name'])){
      $name = $_POST['name'];
      echo "Hello, $name";
    }
    else{
      $name = NULL; echo "You must enter a name.";
    }
  }
?>
Posted in PHP and MySQL, VideoTagged code, coding, data, file, form, get, handle, method, one, php, post, programming, request, single, submission, submitted, tutorial

Recent Posts

  • Creating Gradients in Adobe Illustrator
  • Using the Shaper Tool in Adobe Illustrator
  • Working with Symbols in Adobe Illustrator
  • Using the getElementsByClassName() method in JavaScript
  • Measuring soil moisture with an Arduino

Categories

  • Arduino
  • Coding in C#
  • Computer Science
  • Flash
  • Guides
  • HTML & CSS
  • HTML5 and CSS3
  • HTML5 Canvas
  • ICT
  • Illustrator
  • InDesign
  • Java
  • JavaScript
  • JavaScript
  • Maya 3D
  • OnShape
  • Photoshop
  • PHP and MySQL
  • PlayCanvas
  • Premiere pro
  • Python
  • Responsive web design
  • Uncategorized
  • Unity 3D
  • Video
  • WoofJS
  • Xamarin & C#
Copyright © 2022 CodeMahal – OnePress theme by FameThemes
Privacy - Terms of Use