Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to use $_POST in php.?

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 148
    Comment on it

    $_POST is basically used to accumulate form data after submitting an HTML form .
    $_POST is submit data with method="post". $_POST is also widely used to pass variables.

    You can see below example of $_POST.

    <!DOCTYPE html>
    <html>
    <body>
    
    <form method="post" action="">
       Country: <input type="text" name="country">
       <input type="submit">
    </form>
    
        <?php
    
        if ($_SERVER["REQUEST_METHOD"] == "POST") {
             //here post input field
            $Country_name = $_POST['country']; 
            //now check the condition
             if (empty($Country_name)) {
    
                 echo "Country is empty";
             } else {
                 echo $Country_name;
             }
        }
        ?>
    
    </body>
    </html>
    

    Output will come following:

    If Country_name is empty
    then, output will come

    Country is empty

    If Country_name is not empty
    then output will come
    Country_name which you will give in input field
    suppose you will give "USA" in input field
    then output will come

    USA

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: