Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [php][mysql] Rejestracja sprawdzenie czy hasła są równe
Forum PHP.pl > Forum > Przedszkole
jacus24
Witam mam taki skrypt rejestracji wktórym chce zrobić żeby sprawdzało czy podane hasło = hasło_2 i jeżeli nie będzie równe to informowało by że wpisane hasła nie są takie same. Jak mogę to zrobić?
  1. <?php
  2. include "conn.inc.php";
  3. ?>
  4.  
  5. <html>
  6. <head>
  7. <meta http-equiv="Content-type" content="text/html; charset=iso-8859-2" />
  8. <meta name="Keywords" content="" />
  9. <meta name="Description" content=" " />
  10. <title>IMGAY - Rejestracja</title>
  11. </head>
  12. <body>
  13. <?php
  14.  if (isset($_POST['submit']) && $_POST['submit'] == "Zarejestruj") {
  15.  if ($_POST['login'] != "" &&
  16. $_POST['haslo'] != "" &&
  17. $_POST['haslo_2'] != "" &&
  18. $_POST['email'] !== "" ) {
  19.  
  20. $query = "SELECT login, haslo FROM uzytkownicy WHERE login = '".$_POST['login']."' AND haslo = '".$_POST['haslo']."'";
  21. $result = mysql_query($query) or die(mysql_error());
  22.  
  23. if (mysql_num_rows($result) != 0) {
  24. ?>
  25. <font color="#FF0000"><b>Nazwa użytkownika
  26. <?php echo $_POST['login']; ?>jest już używana. Proszę wybrać inną</b></font>
  27.  
  28. <form action="rejestracja.php" method="post">
  29. Login <input type="text" name="login" size="30" maxlength="40">
  30. Hasło <input type="password" name="haslo" size="30" maxlength="40">
  31. Powtórz hasło <input type="password" name="haslo_2" size="30" maxlength="40" >
  32. Email <input type="text" name="email" size="30" maxlength="40" ></p>
  33. <input type="checkbox" name="regulamin" value="tak" > Akceptuję&nbsp;<a href="regulamin.php">regulamin</a>
  34. <?php $today = date("Y-m-d"); ?>
  35. <input type="submit" name="submit" value="Zarejestruj" > &nbsp;
  36. <input type="reset" value="Wyczyść">
  37. </form>
  38.  
  39. <?php 
  40.  } else {
  41.  
  42.  $query = "INSERT INTO `uzytkownicy` (login, haslo, haslo_2, email, today)
  43.  VALUES (
  44. '".$_POST['login']."',
  45. '".$_POST['haslo']."',
  46. '".$_POST['haslo_2']."',
  47. '".$_POST['email']."',
  48.  '".date("Y-m-d")."'
  49.  );";
  50.  
  51. if(mysql_query($query) == 1)
  52. {
  53. echo 'ok';
  54. }
  55. else
  56. {
  57. }
  58. $_SESSION['user_logged'] = $_POST['login'];
  59. $_SESSION['user_password'] = $_POST['haslo'];
  60. ?>
  61.  
  62. Dziękujemy, <?php echo $_POST['login'] . " " .
  63. $_POST['region']; ?> , za zarejestrowanie się!<br>
  64.  
  65. <?php
  66. header("Refresh: 5: URL=index.php");
  67. echo "Zakonczono proces rejestracji! " .
  68.  "Zostaniesz przeniesiony do oryginalnej strony!<br>";
  69. echo "(Jesli przegladarka nie obsluguje przekierowan, " .
  70.  "<a href=\"index.php\">kliknij tutaj</a>)";
  71. die();
  72. }
  73. } else {
  74. ?>
  75.  
  76. Proszę wypełnić wszystkie pola
  77. <form action="rejestracja.php" method="post">
  78. Login <input type="text" name="login" size="30" maxlength="40">
  79. Hasło <input type="password" name="haslo" size="30" maxlength="40">
  80. Powtórz hasło <input type="password" name="haslo_2" size="30" maxlength="40" >
  81. Email <input type="text" name="email" size="30" maxlength="40" ></p>
  82. <input type="checkbox" name="regulamin" value="tak" > Akceptuję&nbsp;<a href="regulamin.php">regulamin</a>
  83. <?php $today = date("Y-m-d"); ?>
  84. <input type="submit" name="submit" value="Zarejestruj" > &nbsp;
  85. <input type="reset" value="Wyczyść">
  86. </form>
  87.  
  88. <?php
  89.  }
  90. } else {
  91. ?>
  92.  
  93. <form action="rejestracja.php" method="post">
  94. Witamy na stronie rejestracji</p>
  95. Login <input type="text" name="login" size="30" maxlength="40">
  96. Hasło <input type="password" name="haslo" size="30" maxlength="40">
  97. Powtórz hasło <input type="password" name="haslo_2" size="30" maxlength="40" >
  98. Email <input type="text" name="email" size="30" maxlength="40" ></p>
  99. <input type="checkbox" name="regulamin" value="tak" > Akceptuję&nbsp;<a href="regulamin.php">regulamin</a>
  100. <?php $today = date("Y-m-d"); ?>
  101. <input type="submit" name="submit" value="Zarejestruj" > &nbsp;
  102. <input type="reset" value="Wyczyść">
  103. </form>
  104. <?php
  105. }
  106. ?>
  107. </body>
  108. </html>
daris
Zamień:
  1. <?php
  2. $_POST['haslo_2'] != "" &&
  3. ?>

na:
  1. <?php
  2. $_POST['haslo_2'] == $_POST['haslo'] &&
  3. ?>
jacus24
Ok dzięki.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.