पिछले Topic में हमने Form को $_GET Super Global Variable के through handle करना सीखा , इस topic में में $_POST Super Global Variable के बारे में detail से पढ़ेंगे।


$_POST Super Global Variable है means $_POST के through form data access करने के लिए हमें इस global variable बनाने की जरूरत नहीं होती , PHP Script में इसे कहीं भी access कर सकते हैं। $_POST का use PHP में Post / post Method के साथ submit किये गए Form को handle ( Extracting Form Input Data) करने के लिए use किये जाता है। Form को Handle करने का यह सबसे reliable और अच्छा method है।


$_GET की तरह ही $_POST भी Submitted Form Data को एक Array में store करता है , जिसे हम input field name के साथ आसानी से access कर सकते हैं।

$_GET vs $_POST

$_POST और $_GET में सबसे बड़ा difference यही कि $_GET का use हम get / Get method के साथ submit हुए form या किसी URL में query string से data को access करने के लिए किया जाता है , जबकि $_POST का use हम Post / post Method के साथ submit किये गए Form को handle ( Extracting Form Input Data) करने के लिए use किये जाता है।

$_POST Example

File : form.html

Copy Fullscreen Close Fullscreen
<!DOCTYPE html>
<html>
<head>
<title>Form Handling Using $_POSt</title>
</head>
<body>
<form action="post.php" method="post">
<p>Full Name : <input type="text" name="full_name" placeholder="Enter Full Name" /></p>
<p>Age : <input type="number" name="age" min="0" max="120" placeholder="Enter Address" /></p>
<p>Address : <input type="text" name="address" placeholder="Enter Address" /></p>
<p><button type="submit">Submit</button></p>
</form>
</body>
</html>

Another File where we will access form data : post.php

Copy Fullscreen Close Fullscreen
<?php  
/* here we will handle submitted form*/
echo 'Entered All Values : <pre>';
print_r($_GET);
echo '</pre>';
echo 'Your Full Name : '.$_POST['full_name']."<br>";
echo 'Your Age : '.$_POST['age']."<br>";
echo 'Your Age : '.$_POST['address'];
?>
Output
PHP $_POST
After Submit :
PHP $_POST

दूसरी image में आप साफ़ देख सकते हैं कि जिस Form Action में Form को handle करने के लिए जिस file का नाम दिया था , Form Submit होने के बाद Data get / Get method की तरह query string में append नहीं होता है।

Note - $_POST के through हम सिर्फ Post / post method के साथ Submit किये गए Form Data को ही access कर सकते हैं। Get / get method के साथ Submit किये गए Form Data को $_POST के through कभी भी access नहीं कर सकते हैं।

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers