开发者

Can't understand this PHP code

What is this code doing? If Isset, and what are the variables doing, whats the $_POST doing? Can someone explain please?

if (isset($_POST['Submit'])) {
    $title=$_POST['title'];
    $forename = $_POST['forename']; 
    $surname=$_POST ['surname'];
    $dateofbirth=$_POST ['dateofbirth'];
    $gender=$_POST ['gender'];
    $email=$_POST['email']; 
    $phone=$_POS开发者_运维百科T['phone'];
    $passcode1=$_POST ['passcode1'];
    $passcode2=$_POST ['passcode2'];


$_POST contains the data from the form the user submitted.

if(isset($_POST['Submit']))

is checking to see if a form was submitted. There is likely a hidden element with this name, or the submit button was created to include this value.

The remainder of the lines copy*1 the information out of the POST super global into easier to use variables.

(*1 not actually copied, PHP is copy on write)


If a form is being submitted, then it assigns variables.


It will check If the form is submitted set the value of html elements in to the PHP variables that's it.

These variable can be used for further processing and later to store in database.


So here is an attempt to answer your amorphous question.

if (isset($_POST['Submit']))

This line is checking to see if an entry called 'Submit' is present in the $_POST array. isset is a function that checks the existence of variables in PHP.

$_POST is a global variable in PHP that captures the key-value pairs sent in an HTTP POST request. $_POST will contain the result of an HTML form submission in 99% of the use cases.

$title=$_POST['title'];  

is setting the title variable in the PHP script to the title field in the post array. title was probably a text field submitted by a form.

Looking at the use of $_POST in your example code, the request to the php script probably comes from a form that looks like:

<form method="post" name="someForm" action="thatScript.php">
<input type="text" name="title"/>
<input type="text" name="forename"/>
<input type="text" name="surname"/>
... other inputs that correspond to $_POST entries...
<input type="submit" value="Submit" name="Submit"/> <!-- the submit field that is checked in the isset -->
</form>

Notice: <form method="post" This tells the browse to submit the key-value pairs for the form in a post request. If that line read <form metho="get" then the browse would submit the key-value pairs as a get request and the php script would check and use $_GET instead of $_POST.


It checks if the form has been submitted and if its true then values from post array (that are sent by the sending page) are assigned to variables.

for example value for this $_POST['title'] is assigned to variable $title.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜