There is a dedicated command for getting form data in the php Tutorial. $ _ POST [] is the function. Below is a simple example.
<? Php
Echo 'hello, '. $ _ POST ['first _ name'].'! ';
?>
The output is the value of first_name from the form.
A little more complex instance,
$ _ POST ['name'] = trim ($ _ POST ['name']);
If (strlen ($ _ POST ['name']) = 0 ){
$ Errors [] = "Your name is required .";
}
Now, let's make a complete example of $ _ POST.
<? Php
$ User = $ _ POST ['user'];
$ Color = $ _ POST ['color'];
$ Self = $ _ SERVER ['php _ SELF '];
If ($ user! = Null) and ($ color! = Null ))
{
Setcookie ("firstname", $ user, time () + 36000 );
Setcookie ("fontcolor", $ color, time () + 36000 );
Header ("Location: getcookie. php ");
Exit ();
}
?>
<Html>
<Head>
<Title> Set Cookie Data </title>
</Head>
<Body>
<Form action = "<? Php echo ($ self);?> "Method =" post ">
Please enter your first name:
<Input type = "text" name = "user"> <br>
Please choose your favorite font color: <br>
<Input type = "radio" name = "color" value = "# FF0000"> Red
<Input type = "radio" name = "color" value = "#00FF00"> Green
<Input type = "radio" name = "color" value = "# 0000FF"> Blue
<Br>
<Input type = "submit" value = "submit">
</Form>
</Body>
</Html>
Conclusion: the above instance does not perform security processing, but simply obtains the data submitted in the form. We can perform security processing, such as isset () addslashes.