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>
<html>
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
	
	<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>
				  <div class="form-group">
				   <label for="passord">Пароль</label>
				    <input type="password" class="form-control" id="password" name="password">
				  </div>
				  <button type="submit" class="btn btn-default">Отправить</button>
				</form>
			</div>
		</div>
	</div>


</body>
</html>

<?php

var_dump($_POST);

var_dump(empty($_POST['password']));

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

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

0 Comments

Submit a Comment

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

Подписаться на рассылку

Будьте в курсе - получайте последние статьи на свой email

Ваша подписка успешно оформлена

Pin It on Pinterest

Share This