Guest User

Untitled

a guest
Aug 26th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. Form values variables and submission problems
  2. <?php
  3. echo '<style type="text/css">
  4. .error
  5. {
  6. color: red;
  7. }
  8. </style>';
  9.  
  10. $error = false;
  11.  
  12. if (isset($_POST['submitted']))
  13. {
  14.  
  15. if (empty($_POST['username']) || empty($_POST['password']))
  16. {
  17. $error = TRUE;
  18. }
  19.  
  20. if (!$error && $_POST['username']=='test' && $_POST['password']=='abc123') {
  21.  
  22. echo '<p>Correct. Thank you for entering.<p/>';
  23. }
  24.  
  25. else
  26. {
  27. echo '<p>Sorry, no access.</p>
  28. ';
  29. }
  30.  
  31. }
  32. ?>
  33. <form action="" method="post">
  34. Username: <input type="text" name="username" size="20" value="<?php
  35. if (isset($_POST['submitted']) && !empty($_POST['username']))
  36. {
  37. echo $_POST['username'];
  38. } ?>" />
  39. <?php
  40. if (isset($_POST['submitted']) && empty($_POST['username']))
  41. {
  42. echo '<span class="error">Please enter a username.</span>';
  43. }
  44. ?>
  45. <br />Password: <input type="password" name="password" size="20" value="<?php
  46. if (isset($_POST['submitted']) && !empty($_POST['password']))
  47. {
  48. echo $_POST['password'];
  49. } ?>" />
  50. <?php
  51. if (isset($_POST['submitted']) && empty($_POST['password']))
  52. {
  53. echo '<span class="error">Please enter a password.</span>';
  54. }
  55. ?>
  56. <br /><input type="submit" value="Log in" />
  57. <br /><input type="hidden" name="submitted" value="true" />
  58. </form>
  59.  
  60. <style type="text/css">
  61. .error {
  62. color: red;
  63. }
  64. </style>
  65. <?php
  66.  
  67. $submitted = isset($_POST['submitted']);
  68. $userName = isset($_POST['username']) ? $_POST['username'] : null;
  69. $password = isset($_POST['password']) ? $_POST['password'] : null;
  70.  
  71. if($submitted) {
  72. if (!$userName || !$password) {
  73. echo '<p class="error">Please go back and fill the inputs.</p>';
  74. } elseif($userName == 'test' && $password == 'abc123') {
  75. echo '<p>Correct. Thank you for entering.<p/>';
  76. } else {
  77. echo '<p class="error">Sorry, no access.</p>';
  78. }
  79. } else {
  80. ?>
  81. <form action="" method="post">
  82. Username: <input type="text" name="username" size="20" value="<?php echo $userName; ?>" />
  83. <br />
  84. Password: <input type="password" name="password" size="20" value="" />
  85. <br /><input type="submit" value="Log in" />
  86. <br /><input type="hidden" name="submitted" value="true" />
  87. </form>
  88. <?php } ?>
  89.  
  90. $submitted = isset($_POST['submitted']);
  91. $userName = isset($_POST['username']) ? $_POST['username'] : null;
  92. $password = isset($_POST['password']) ? $_POST['password'] : null;
  93.  
  94. if($submitted)
  95. {
  96. if (!$userName || !$password) {
  97. echo '<p class="error">Please go back and fill the inputs.</p>';
  98. }
  99. }
Add Comment
Please, Sign In to add comment