Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Rejestracja
Forum PHP.pl > Forum > Przedszkole
Eleeist
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. ?>
nospor
= - przypisanie
== - porównanie

Patrz proszę uważniej jak piszesz zanim polecisz na forum z taką błachostką.
Eleeist
ph34r.gif Oj, ale głupi błąd.. Przepraszam i dziękuję za jego wytknięcie.
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.