Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Rejestracja Brak reakcji!
Forum PHP.pl > Forum > PHP
Marecki669
Witam,
Mam problem otóż gdy wypełnię formularz nic się nie dzieje nie wiem dlaczego, gdy kliknę rejestruj strona się odświeża i jest pokazany od nowa formularz. Użytkownika nie dodaje do bazy danych

Plik signup.php:
  1. <?php
  2.  
  3. include ("appearance/header.php");
  4. include ("modules/signup.functions.php");
  5. include ("include/ff.settings.php");
  6.  
  7. if (isset($_POST['signup'])) { $do = new_signup(); }
  8.  
  9. ?>
  10.  
  11. <?php echo $do; ?>
  12.  
  13. <?php if (!$_GET['do']) { ?>
  14.  
  15. <form action="signup.php" method="post" id="regformstep1">
  16. <ol>
  17. <li>
  18. <label>Imię: <span class="red">*</span></label>
  19. <input type="text" id="imie" name="firstname" class="text" />
  20. </li>
  21. <li>
  22. <label>Nazwisko: <span class="red">*</span></label>
  23. <input type="text" id="nazwisko" name="lastname" class="text" />
  24. </li>
  25. <li>
  26. <label>Email: <span class="red">*</span></label>
  27. <input type="text" id="email" name="email" class="text" />
  28. </li>
  29. <li>
  30. <label>Powtórz email: <span class="red">*</span></label>
  31. <input type="text" id="pemail" name="confrim_email" class="text" />
  32. </li>
  33. <li>
  34. <label>Hasło: <span style class="red">*</span></label>
  35. <input type="password" id="haslo" name="password" class="text" />
  36. </li>
  37. <li>
  38. <label >Powtórz hasło: <span class="red">*</span></label>
  39. <input type="password" id="phaslo" name="confrim_password" class="text" />
  40. </li>
  41. <br />
  42. <br />
  43. <br />
  44. <br />
  45. <label><img src="security.image.php" width="144" height="30" /></label>
  46. <br />
  47. <br />
  48. <li>
  49. <label>Kod zabezpieczający: <span class="red">*</span></label>
  50. <input name="security" id="security" type="text" class="text" />
  51. </li>
  52. <li>
  53. <label><a href="terms.php?do=terms" class="text_4_css_bold">Akceptuje Zasady!</a></label>
  54. <input type="checkbox" name="terms" /></td>
  55. </li>
  56.  
  57. <li class="buttons">
  58. <input type="submit" name="signup" id="signup" class="przycisk" value="Zarejestruj Mnie"/>
  59. <div class="clr"></div></li><br />
  60.  
  61.  
  62. </ol>
  63. </form>
  64.  
  65.  
  66. <?php } else if ($_GET['do'] == 'complete') { ?>
  67. <table width="100%" border="0" cellpadding="4" cellspacing="2" class="text_2_css">
  68. <tr>
  69. <td>Rejestracja Udana!</td>
  70. </tr>
  71. </table>
  72. <?php } ?>
  73.  
  74.  
  75.  
  76. <?php
  77.  
  78. include ("appearance/footer.php");
  79.  
  80. ?>


plik signup.functions.php:
  1. <?php
  2.  
  3.  
  4. function message_status($type, $message) {
  5.  
  6. if ($type == 'error') {
  7.  
  8. return '<table width="100%" border="0" class="warning_message">
  9. <tr><td width="1%"><img src="/images/icons/008.GIF" hspace="6" vspace="6" /></td>
  10. <td width="99%">'.$message.'</td></tr></table>';
  11.  
  12. } else if ($type == 'done') {
  13.  
  14. return '<table width="100%" border="0" class="complete_message">
  15. <tr><td width="1%"><img src="/images/icons/015.GIF" hspace="6" vspace="6" /></td>
  16. <td width="99%">'.$message.'</td></tr></table>';
  17.  
  18. }
  19.  
  20. }
  21.  
  22.  
  23. // rejestracja
  24. function new_signup() {
  25.  
  26. global $lang, $ff_settings;
  27.  
  28. if (isset($_POST['signup'])) {
  29.  
  30. $email_exists = sql_query("SELECT * FROM users WHERE email = '".$_POST['email']."'");
  31. $ban_exists = sql_query("SELECT * FROM banned WHERE banned_email = '".$_POST['email']."'");
  32. $username = $data['firstname']. " " .$data['lastname'];
  33.  
  34. } else if (empty($_POST['firstname'])) {
  35.  
  36. return message_status('error', 'Wypełnij Pole!');
  37.  
  38. } else if (empty($_POST['lastname'])) {
  39.  
  40. return message_status('error', 'Wypełnij Pole!');
  41.  
  42. } else if (empty($_POST['password'])) {
  43.  
  44. return message_status('error', 'Wypełnij Pole!');
  45.  
  46. } else if ($_POST['password'] != $_POST['confrim_password']) {
  47.  
  48. return message_status('error', 'Hasła nie są takie same!');
  49.  
  50. } else if (empty($_POST['email'])) {
  51.  
  52. return message_status('error', 'Wypełnij Pole!');
  53.  
  54. } else if ($_POST['email'] != $_POST['confrim_email']) {
  55.  
  56. return message_status('error', 'Emaile nie są takie same!');
  57.  
  58. } else if (mysql_num_rows($ban_exists) != '0') {
  59.  
  60. return message_status('error', 'Email zbanowany!');
  61.  
  62. } else if (mysql_num_rows($email_exists) != '0') {
  63.  
  64. return message_status('error', 'Email zajęty!');
  65.  
  66. } else if (strtoupper($_POST['security']) != $_SESSION['code']) {
  67.  
  68. return message_status('error', 'Kod bezpieczeństwa jest zły!');
  69.  
  70. } else if ($_POST['terms'] != 'on'){
  71.  
  72. return message_status('error', 'Zaakceptuj Zasady!');
  73.  
  74.  
  75. } else {
  76.  
  77. sql_query("INSERT INTO users (username, password, email, firstname, lastname, user_created, user_login) VALUES ('".$username."',
  78. '".md5($_POST['password'])."', '".$_POST['email']."', '".$_POST['firstname']."', '".$_POST['lastname']."', '".time()."', '0')");
  79.  
  80.  
  81. include("lang/emails.php");
  82.  
  83. mail($_POST['email'], $welcome_subject, $welcome_email.$footers, $headers);
  84.  
  85. header('Location: signup.php?do=complete');
  86.  
  87. } }
  88.  
  89.  
  90. ?>
radziopoke
Szukałem i znalazłem.
ten warunek:
  1. if (isset($_POST['signup']))

wykona się gdy zostanie wysłany formularz, a żeby zapisało się do bazy danych musi być spełnione to:
  1. else {
  2.  
  3. sql_query("INSERT INTO users (username, password, email, firstname, lastname, user_created, user_login) VALUES ('".$username."',
  4. '".md5($_POST['password'])."', '".$_POST['email']."', '".$_POST['firstname']."', '".$_POST['lastname']."', '".time()."', '0')");
  5.  
  6.  
  7. include("lang/emails.php");
  8.  
  9. mail($_POST['email'], $welcome_subject, $welcome_email.$footers, $headers);
  10.  
  11. header('Location: signup.php?do=complete');
  12.  
  13. } }

co mówi samo przez się że nie wykonają się dwie rzeczy naraz (gdyż drugi warunek to warunek else) dlatego wykona się to co jest w pierwszym warunku się wykona a potem omija wszystkie inne warunki if.


A po drugie
  1. if (isset($_POST['signup'])) {
  2.  
  3. $email_exists = sql_query("SELECT * FROM users WHERE email = '".$_POST['email']."'");
  4. $ban_exists = sql_query("SELECT * FROM banned WHERE banned_email = '".$_POST['email']."'");
  5. $username = $data['firstname']. " " .$data['lastname'];
  6.  
  7. }

W tym kodzie korzystasz ze zmiennej $_POST['email'] której poprawność sprawdzasz dopiero w warunku
  1. else if (empty($_POST['email']))


I w ogóle masz cały blok if z else if do zmiany. Jak to się mówi trochę logiki i człowiek się gubi smile.gif
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.