Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //File 1
- <html>
- <head>
- <title> Form</title>
- </head>
- <body>
- <form action="form_processing.php" method="post">
- Username: <input type="text" name="username" value=""><br/>
- password: <input type="password" name="password" value=""><br/>
- <br/>
- <input type="submit" name="submit" value="Submit">
- </form>
- </body>
- </html>
- //File 2
- <?php
- if(isset($_POST['submit'])){ //checks if the submit button has been pressed
- $username = $_POST['username'];
- $password = $_POST['password'];
- }else{ //When the submit button isn't pressed
- $username = null;
- $password = null;
- }
- /* //Alternative way to check form submission
- $username = isset($_POST['username'])?$_POST['username']: "";
- $password = isset($_POST['password'])?$_POST['password']: "";
- */
- //the following codes are interpretion of the code above.
- /* if(isset($_POST['username'])) //Detecting if the form has submitted the username value
- $username = $_POST['username']; //Gets the username through the superglobal POST array from index.php
- else
- $username = null; //Set Null as the default value when form date is not posted
- if(isset($_POST['password'])) //Detecting if the form has submitted the password value
- $password = $_POST['password']; //Gets the password through the superglobal POST array from index.php
- else
- $password = null; //Set Null as the default value when form date is not posted
- */
- echo $username."<br/>"; //prints the username
- echo $password; //prints the password ;) Don't recommend to do in real life
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement