Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Form values variables and submission problems
- <?php
- echo '<style type="text/css">
- .error
- {
- color: red;
- }
- </style>';
- $error = false;
- if (isset($_POST['submitted']))
- {
- if (empty($_POST['username']) || empty($_POST['password']))
- {
- $error = TRUE;
- }
- if (!$error && $_POST['username']=='test' && $_POST['password']=='abc123') {
- echo '<p>Correct. Thank you for entering.<p/>';
- }
- else
- {
- echo '<p>Sorry, no access.</p>
- ';
- }
- }
- ?>
- <form action="" method="post">
- Username: <input type="text" name="username" size="20" value="<?php
- if (isset($_POST['submitted']) && !empty($_POST['username']))
- {
- echo $_POST['username'];
- } ?>" />
- <?php
- if (isset($_POST['submitted']) && empty($_POST['username']))
- {
- echo '<span class="error">Please enter a username.</span>';
- }
- ?>
- <br />Password: <input type="password" name="password" size="20" value="<?php
- if (isset($_POST['submitted']) && !empty($_POST['password']))
- {
- echo $_POST['password'];
- } ?>" />
- <?php
- if (isset($_POST['submitted']) && empty($_POST['password']))
- {
- echo '<span class="error">Please enter a password.</span>';
- }
- ?>
- <br /><input type="submit" value="Log in" />
- <br /><input type="hidden" name="submitted" value="true" />
- </form>
- <style type="text/css">
- .error {
- color: red;
- }
- </style>
- <?php
- $submitted = isset($_POST['submitted']);
- $userName = isset($_POST['username']) ? $_POST['username'] : null;
- $password = isset($_POST['password']) ? $_POST['password'] : null;
- if($submitted) {
- if (!$userName || !$password) {
- echo '<p class="error">Please go back and fill the inputs.</p>';
- } elseif($userName == 'test' && $password == 'abc123') {
- echo '<p>Correct. Thank you for entering.<p/>';
- } else {
- echo '<p class="error">Sorry, no access.</p>';
- }
- } else {
- ?>
- <form action="" method="post">
- Username: <input type="text" name="username" size="20" value="<?php echo $userName; ?>" />
- <br />
- Password: <input type="password" name="password" size="20" value="" />
- <br /><input type="submit" value="Log in" />
- <br /><input type="hidden" name="submitted" value="true" />
- </form>
- <?php } ?>
- $submitted = isset($_POST['submitted']);
- $userName = isset($_POST['username']) ? $_POST['username'] : null;
- $password = isset($_POST['password']) ? $_POST['password'] : null;
- if($submitted)
- {
- if (!$userName || !$password) {
- echo '<p class="error">Please go back and fill the inputs.</p>';
- }
- }
Add Comment
Please, Sign In to add comment