Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Przeniesienie fraz
Eleeist
post 21.09.2011, 11:20:31
Post #1





Grupa: Zarejestrowani
Postów: 48
Pomógł: 0
Dołączył: 25.03.2009

Ostrzeżenie: (0%)
-----


Witam,

Rozmyślam właśnie jak przenieść frazy z dołu skryptu (te else z errorami) nad form z rejestracją (kod HTML na górze). Pierwsze co mi przyszło do głowy to przypisanie erroru do zmiennej i jego wyświetlenie, ale szybko zrozumiałem, że tak łatwo się tego nie da zrobić (chyba..).

Szukam po prostu pomysłu/podpowiedzi jak można taki problem rozwiązać.

  1. <?php
  2.  
  3. include("header.php");
  4.  
  5. ?>
  6.  
  7. <html>
  8. <head>
  9. <title>Register</title>
  10. </head>
  11. <body>
  12. <h1>Register</h1>
  13.  
  14. <?php
  15.  
  16. if (!isset($_SESSION['username'])) {
  17.  
  18. ?>
  19.  
  20. <p>
  21. <form action='register.php' method='POST'>
  22. <table>
  23. <tr>
  24. <td>
  25. Your full name:
  26. </td>
  27. <td>
  28. <input type="text" name="fullname" />
  29. </td>
  30. </tr>
  31. <tr>
  32. <td>
  33. Choose a username:
  34. </td>
  35. <td>
  36. <input type="text" name="username" />
  37. </td>
  38. </tr>
  39. <tr>
  40. <td>
  41. Choose a password:
  42. </td>
  43. <td>
  44. <input type="password" name="password" />
  45. </td>
  46. </tr>
  47. <tr>
  48. <td>
  49. Repeat your password:
  50. </td>
  51. <td>
  52. <input type="password" name="repeatpassword" />
  53. </td>
  54. </tr>
  55. <tr>
  56. <td>
  57. <input type="submit" name="submit" value="Register" />
  58. </td>
  59. </tr>
  60. </table>
  61. </form>
  62. </body>
  63. </html>
  64.  
  65. <?php
  66.  
  67. // Get data from the form.
  68.  
  69. $fullname = strip_tags($_POST['fullname']);
  70. $username = strtolower(strip_tags($_POST['username']));
  71. $password = strip_tags($_POST['password']);
  72. $repeatpassword = strip_tags($_POST['repeatpassword']);
  73. $date = date("Y-m-d");
  74. $submit = $_POST['submit'];
  75.  
  76. // Check if form is submitted.
  77.  
  78. if ($submit) {
  79.  
  80. // Connect to database server and select database.
  81.  
  82. $connect = mysql_connect("x","x","x");
  83.  
  84. $namecheck = mysql_query("SELECT username FROM users WHERE username='$username'");
  85. $count = mysql_num_rows($namecheck);
  86.  
  87. // Check if all data is present..
  88.  
  89. if ($username && $fullname && $password && $repeatpassword) {
  90.  
  91. // Check if username already exists.
  92.  
  93. if ($count == 0) {
  94.  
  95. // Check if passwords match.
  96.  
  97. if ($password == $repeatpassword) {
  98.  
  99. // Check the length of username and full name.
  100.  
  101. if (strlen($username) < 25 || strlen($fullname) < 25) {
  102.  
  103. // Check the length of password.
  104.  
  105. if (strlen($password) < 25 || strlen($password) > 6) {
  106.  
  107. // If everything do this...
  108.  
  109. // Encrypt passwords.
  110.  
  111. $password = md5($password);
  112. $repeatpassword = md5($repeatpassword);
  113.  
  114. // Insert user into database and show success message.
  115.  
  116. $queryreg = mysql_query("INSERT INTO users VALUES ('','$fullname','$username','$password','$date')");
  117.  
  118. die("You have been <b>registered</b>. Click <a href='index.php'>here</a> to return to login page.");
  119.  
  120. }else {echo "The lenght of password must be between 6 and 25 characters.";}
  121.  
  122. }else {echo "The username and full name cannot exceed 25 characters each.";}
  123.  
  124. }else {echo "The passwords do not match.";}
  125.  
  126. }else {echo "This user already exists.";}
  127.  
  128. }else {echo "All fields are required.";}
  129.  
  130. }
  131.  
  132.  
  133. }else {
  134.  
  135. echo "You are already registered and logged in. Click <a href='members.php'>here</a> to enter the members area.<br />";
  136.  
  137. }
  138.  
  139.  
  140. footer();
  141.  
  142. ?>
Go to the top of the page
+Quote Post
nospor
post 21.09.2011, 11:22:40
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




1) Otwierasz edytor
2) Zaznaczasz wybrany fragment
3) wycinasz
4) a następnie wklejasz wyżej.

Wiem, że to skomplikowana operacja, ale naprawdę mogłeś spróbować samemu to wpierw zrobić.


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
phpion
post 21.09.2011, 11:24:45
Post #3





Grupa: Moderatorzy
Postów: 6 072
Pomógł: 861
Dołączył: 10.12.2003
Skąd: Dąbrowa Górnicza




@nospor:
Daj sobie "Pomógł" smile.gif
Go to the top of the page
+Quote Post
Eleeist
post 21.09.2011, 11:27:03
Post #4





Grupa: Zarejestrowani
Postów: 48
Pomógł: 0
Dołączył: 25.03.2009

Ostrzeżenie: (0%)
-----


Rozwijając mój poprzedni post:

Errory wyskakują po kliknięciu w submit, jeżeli któryś z if() jest nieprawdziwy. Przecież nie przeniosę else na samą górę...
Go to the top of the page
+Quote Post
nospor
post 21.09.2011, 11:28:36
Post #5





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Mówisz o ostatnim ELSE? A kto ci go każe tam przenosić? Przecież chciałeś przenieść kod sprawdzający formularz.


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
Eleeist
post 21.09.2011, 11:34:42
Post #6





Grupa: Zarejestrowani
Postów: 48
Pomógł: 0
Dołączył: 25.03.2009

Ostrzeżenie: (0%)
-----


Dalej się nie rozumiemy.

Wchodzisz na stronę, wyświetla ci się ładny formularz rejestracyjny, wypełniasz go ale np. zapomnisz o jednym polu (zostawisz puste). Wtedy else wywala error "All fields are required.". Tyle, że error wyświetla się POD formularzem rejestracyjnym. Ja chciałbym aby wyświetlał się NAD nim. Nie mogę tego else z errorem przenieść NAD formularz, bo if(), do którego jest to else, znajdzie się pod else i kod nie będzie działał... tongue.gif

Ten post edytował Eleeist 21.09.2011, 11:35:16
Go to the top of the page
+Quote Post
nospor
post 21.09.2011, 11:36:47
Post #7





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Po pierwsze: nie pokazuj mi języka bez powodu. To że TY nie rozumiesz prostej rzeczy, nie jest powodem do pokazywania mi języka

Po drugie: ale ja ci mówie byś przeniósł nad formularz cały kod sprawdzający formularz a nie tylko ELSE. Czytaj co się do ciebie pisze.


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 19.07.2025 - 01:29