SoFunction
Updated on 2025-04-08

Talk about PHP syntax (3)

Author: Hua Honglang
text:
The above article ("Talking about PHP Syntax (2)") mentioned that it is very convenient for PHP to submit form information. However, how long is the life cycle of the variable in the submitted form information? This article will talk about this issue.
The parameters of the form will be passed to the next handler, and there is no doubt about this. Because, we have had such examples. But will it continue to be passed to the next handler?
The answer is no! The parameters submitted by a Form form are only passed to the first handler, and it will not work in the next handler. Let’s take a look at the following example:
document:
<html>
<head><title>Form Submission</title>
</head>
<body>
<form action="">
Enter the singer you think is good: <input type="text" name="start" size=20 >
<input type="submit" value="It's him, send it out">
</form>
</body>
</html>

document:
<?php
echo "<html><body>";
echo "You like $start, right?<br>";
echo "<a href=\"\">Try to pass it on again</a>";
echo "</body></html>";
?>
document:
<?php
echo "<html><body>";
echo "Do you say $start is OK?";
echo "</body></html>";
?>
From the above example, we can see that the result of the processing is (assuming that we entered "*"):

You like Jacky Cheung, right?
Try to pass on it again

It means that the form has submitted the variable $start, and in the display result, if we click the link "try whether it will be passed on again", the processing result of Newp is:

Did you say ok?

Obviously, $start was not passed to. But how do we extend the life cycle of $start? Actually, this is very simple, just use the parameter passing method. As in New York, we can change it to this:
<?php
echo "<html><body>";
echo "You like $start, right?<br>";
echo "<a href=\"?start=$start\">Try to pass it on again</a>";
echo "</body></html>";
?>
Clear the program, you will find that you just add the sentence "?start=$start" to the end, and the function of this is parameter passing. For example: .Ni/?no=1 The following ? is a parameter, no is the parameter name, and its value is 1. This will produce the variable $no in the program, whose value is 1. If you pass more than two New parameters, separate them with &. For example: /?no=2&debug=1
In order to extend the life cycle of parameters, we can also use cookies or sessions to achieve this. We will not describe them more here. You will see their usage in future articles.

--(to be continued)--