Post: [ php][tut] GET and POST variables explained.
05-10-2011, 12:34 AM #1
(adsbygoogle = window.adsbygoogle || []).push({});
Originally posted by 039

Here's a small tutorial on how to get data from GET and POST forms and store them in a variable. for a tutorial on forms, look You must login or register to view this content.

[size=large][color=#E0FFFF]1. GET variables [/color][/size]
    
<html>
<head>
<title> PHP forms </title>
</head>
<body>
<form method='GET' action='index.php'>
Your name:<input type='text' name='name'> <br>
Your age :<input type='text' name='age'> <br>
Your gender:<input type='text' name='gender'> <br>
<input type='submit'>
</form>

<?php

$name=$_GET['name'];
$gender=$_GET['gender'];
$age=$_GET['age'];

echo "Welcome $name, you're a $gender and you're $age old.";

?>

When the method GET is used - Note : I don't recommend using GET variables for secure things like logging in - You can store that data by putting it in a variable with the supervariable $_GET and in the [] you put the name of the input.

[size=large][color=#E0FFFF]2. POST variables [/color][/size]

    
<html>
<head>
<title> PHP forms </title>
</head>
<body>
<form method='POST' action='index.php'>
Your name:<input type='text' name='name'> <br>
Your age :<input type='text' name='age'> <br>
Your gender:<input type='text' name='gender'> <br>
<input type='submit'>
</form>

<?php

$name=$_POST['name'];
$gender=$_POST['gender'];
$age=$_POST['age'];

echo "Welcome $name, you're a $gender and you're $age old.";



?>


When the method POST is used (recommended!)You can store that data by putting it in a variable with the supervariable $_POST and in the [] you put the name of the input.


source You must login or register to view this content.

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo