Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Przeniesienie fraz
Eleeist
post
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

Posty w temacie


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 Aktualny czas: 20.08.2025 - 12:06