Submit form to php

Home » Tutorials » PHP » Submit form to php
In this lesson you will learn how to submit form to php. Each of you were registering on sites, entering login and password and so on. After this lesson you can submit any data to server and make simple validation.
You can submit form to the server with two methods – GET or POST. Difference between them, that data with GET method pass with url. You understand, passing login and password is not a good idea. You need to use POST method. On the server some script recieves data from html form. But where do we find this data. PHP put this data to global array – $_POST or $_GET (depending on the submit method). Like any other array, these arrays have got keys. Keys are name attributes from html form. Values are user data.

Code lesson

<!DOCTYPE html>
	<meta charset="UTF-8">
	<link rel="stylesheet" href="">
	<div class="container">
		<div class="row">
			<div class="col-md-12">
				<form action="form.php" method="post">
				  <div class="form-group">
				    <label for="login">Логин</label>
				    <input type="text" class="form-control" id="login" name="login">
				  <div class="form-group">
				   <label for="passord">Пароль</label>
				    <input type="password" class="form-control" id="password" name="password">
				  <button type="submit" class="btn btn-default">Отправить</button>





$login = $_POST['login'];
$password = $_POST['password'];

if(empty($login) || empty($password)) {
	echo "Error";
} else {
	echo "Вы используете логин $login и пароль $password";


Submit a Comment

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

The reCAPTCHA verification period has expired. Please reload the page.

Pin It on Pinterest

Share This