PHP Form HandlingThe most important thing to notice when dealing with HTML forms and PHP is that any form element in an HTML page will automatically be available to your PHP scripts. <html>
<body> <<form action="welcome.php" method="post"> Name: <input type="text" name="fname" /> Age: <input type="text" name="age" /> <input type="submit" /> </form> </body> </html> Example: <html>
<body> Welcome <?php echo $_POST["fname"]; ?>!<br /> You are <?php echo $_POST["age"]; ?> years old. </body> </html> The built-in $_GET function is used to collect values in a form with method="get". The $_GET FunctionThe built-in $_GET function is used to collect values from a form sent with method="get". Information sent from a form with the GET method is visible to everyone (it will be displayed in the browser's address bar) and has limits on the amount of information to send (max. 100 characters). <form action="welcome.php" method="get">
http://www.w3schools.com/welcome.php?fname=Peter&age=37Name: <input type="text" name="fname" /> Age: <input type="text" name="age" /> <input type="submit" /> </form> Welcome <?php echo $_GET["fname"]; ?>.<br /> You are <?php echo $_GET["age"]; ?> years old! When to use method="get"?When using method="get" in HTML forms, all variable names and values are displayed in the URL.Note: This method should not be used when sending passwords or other sensitive information! However, because the variables are displayed in the URL, it is possible to bookmark the page. This can be useful in some cases. Note: The get method is not suitable for large variable values; the value cannot exceed 100 characters. The built-in $_POST function is used to collect values in a form with method="post". The $_POST Function <form action="welcome.php" method="post">
http://www.w3schools.com/welcome.phpName: <input type="text" name="fname" /> Age: <input type="text" name="age" /> <input type="submit" /> </form> Welcome <?php echo $_POST["fname"]; ?>!<br /> You are <?php echo $_POST["age"]; ?> years old. When to use method="post"? Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send. However, because the variables are not displayed in the URL, it is not possible to bookmark the page. The PHP $_REQUEST Function Welcome <?php echo $_REQUEST["fname"]; ?>!<br />
You are <?php echo $_REQUEST["age"]; ?> years old. The PHP date() function is used to format a time and/or date.
|
|