PHP ফরম এর GET এবং POST Method এর ব্যবহার

Author: Al-mamun Sarkar Date: 2020-04-16 01:37:36

PHP ফরম এর GET এবং Post Method এর ব্যবহার। এই লিসন এ আমারা দেখব কিভাবে পিএইচপি দিয়ে ফরম থেকে GET এবং POST Method এ DATA নিতে হয় । 

 

Source Code:

form_get.php

<!DOCTYPE html>
<html>
<head>
	<title> This is form </title>
</head>
<body>

<form action="get_action.php" method="get">
	Name: <input type="text" name="name"> <br/> <br/>
	Email: <input type="text" name="email"> <br/> <br/>

	<input type="submit" value="Save">
</form>

</body>
</html>

get_action.php

$email = $_GET['email']; 

echo "This is get Action page. <br/>";
echo "Name is : $name <br/>";
echo "Email is : $email <br/>";

 

form_post.php

<!DOCTYPE html>
<html>
<head>
	<title> This is form </title>
</head>
<body>

<form action="post_action.php" method="POST">
	Name: <input type="text" name="name"> <br/> <br/>
	Email: <input type="text" name="email"> <br/> <br/>
	<input type="checkbox" name="book[]" value="Bangla"> Bangla.  <br/>
	<input type="checkbox" name="book[]" value="English"> English.  <br/> <br/> 
	<input type="submit" value="Save">
</form>
<br/> <br/>
<a href="test_get.php?num=45"> Go to test </a>

</body>
</html>

post_action.php

if($_POST) {
	$name = $_POST['name']; 
	$email = $_POST['email']; 
	$books = isset($_POST['book']) ? $_POST['book'] : []; 

	echo "Name is : $name <br/>";
	echo "Email is : $email <br/>";
	print_r($books);
} else {
	header('Location: form_post.php');
}

 

test_get.php:

echo $_GET['num'];