Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Rejestracja
Eleeist
post 21.09.2011, 10:31:52
Post #1





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

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


Witam,

Stworzyłem taki prosty system rejestracji użytkowników do bazy danych ze sprawdzaniem pól.

Problemem jest część, która sprawdzą czy użytkownik o takim samym username jest już w bazie. W teorii działa (wyświetla np. 1 jak jest 1, 0 jak jest 0 użytkowników o takim samym nicku w bazie), jednak po wstawieniu do if($count = 0) przestaje działać. Cokolwiek bym nie wpisał wyświetla się komunikat "That user already exists.". Baza jest czyściutka, bo testuję.

Wklejam tylko część (bez forma itp.)

Byłbym bardzo wdzięczny za wskazówki lub ew. pomoc.

  1. <?php
  2.  
  3. if (!isset($_SESSION['username'])) {
  4.  
  5. // Get data from the form.
  6.  
  7. $fullname = strip_tags($_POST['fullname']);
  8. $username = strtolower(strip_tags($_POST['username']));
  9. $password = strip_tags($_POST['password']);
  10. $repeatpassword = strip_tags($_POST['repeatpassword']);
  11. $date = date("Y-m-d");
  12. $submit = $_POST['submit'];
  13.  
  14. // Check if form is submitted.
  15.  
  16. if ($submit) {
  17.  
  18. // Connect to database server and select database.
  19.  
  20. $connect = mysql_connect("x","x","x");
  21.  
  22. $namecheck = mysql_query("SELECT username FROM users WHERE username='$username'");
  23. $count = mysql_num_rows($namecheck);
  24.  
  25. // Check if all data is present..
  26.  
  27. if ($username && $fullname && $password && $repeatpassword) {
  28.  
  29. // Check if username already exists.
  30.  
  31. if ($count = 0) {
  32.  
  33. // Check if passwords match.
  34.  
  35. if ($password == $repeatpassword) {
  36.  
  37. // Check the length of username and full name.
  38.  
  39. if (strlen($username) < 25 || strlen($fullname) < 25) {
  40.  
  41. // Check the length of password.
  42.  
  43. if (strlen($password) < 25 || strlen($password) > 6) {
  44.  
  45. // If everything is ok do this...
  46.  
  47. // Encrypt passwords.
  48.  
  49. $password = md5($password);
  50. $repeatpassword = md5($repeatpassword);
  51.  
  52. // Insert user into database and show success message.
  53.  
  54. $queryreg = mysql_query("INSERT INTO users VALUES ('','$fullname','$username','$password','$date')");
  55.  
  56. die("You have been <b>registered</b>. Click <a href='index.php'>here</a> to return to login page.");
  57.  
  58. }else {echo "The lenght of password must be between 6 and 25 characters.";}
  59.  
  60. }else {echo "The username and full name cannot exceed 25 characters each.";}
  61.  
  62. }else {echo "The passwords do not match.";}
  63.  
  64. }else {echo "This user already exists.";}
  65.  
  66. }else {echo "All fields are required.";}
  67.  
  68. }
  69.  
  70. }else {echo "You are already registered and logged in. Click <a href='members.php'>here</a> to enter the members area.";}
  71.  
  72. ?>
Go to the top of the page
+Quote Post
nospor
post 21.09.2011, 10:34:43
Post #2





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




= - przypisanie
== - porównanie

Patrz proszę uważniej jak piszesz zanim polecisz na forum z taką błachostką.


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

"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:15:15
Post #3





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

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


ph34r.gif Oj, ale głupi błąd.. Przepraszam i dziękuję za jego wytknięcie.
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 - 11:17