Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP][MYSQL]Problem z rejestracją...
-Mefggt-
post
Post #1





Goście







Napisałem sobie rejestrację do panelu logowania i mam problem. Niby sprawdza czy istnieje użytkownik już taki podczas rejestracji i czy hasła się zgadzają no i czy mail już taki jest w bazie ale jak zmienię e-mail i hasła się zgadzają to rejestruje mimo że użytkownik już istnieje w bazie. Co jest nie tak? Kod:

  1. <?php
  2.  
  3. mysql_connect ('localhost','root','some');
  4.  
  5. $nick= $_POST['user'];
  6. $password= $_POST['password'];
  7. $email= $_POST['email'];
  8. $repassword= $_POST['repassword'];
  9. $user= $nick;
  10. $mail= $email;
  11.  
  12. $use= mysql_query ("SELECT user FROM base WHERE user='".$_POST['user']."' AND email='".$_POST['email']."'");
  13.  
  14. while ($check= mysql_fetch_assoc($use)) {
  15.  
  16. $chuser= $check['user'];
  17. $chmail= $check['email'];
  18.  
  19. }
  20.  
  21. if (!empty($nick) && !empty($password) && !empty($email) && !empty($repassword)) {  // => Type all information
  22.  
  23. if ($user!= $chuser && $repassword== $password && $mail!= $chmail) {
  24.  
  25. $records= "INSERT INTO `base` (`user`, password, email) VALUES ('$nick','$password','$email');";
  26. mysql_query ($records);
  27.  
  28. echo 'You have been registered :)';
  29.  
  30. }
  31.  
  32. else {
  33.  
  34. echo 'This user already exists/ Typed password are not the same/E-mail is registered';
  35.  
  36. }
  37.  
  38. } //end empty
  39.  
  40. else {
  41.  
  42. echo 'Type all information';
  43.  
  44. }
  45.  
  46. ?>


  1. <!DOCTYPE html
  2. PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
  5. <meta http-equiv="Content-type" content="application/xhtml+xml; charset=iso-8859-2" />
  6. <meta name="Description" content="Something" />
  7. <meta name="Keywords" content="Something" />
  8. <meta name="Author" content="Author " />
  9. <link rel="Stylesheet" href="style.css" type="text/css" />
  10. <title>Title</title>
  11. </head>
  12.  
  13. <form action="register.php" method="post">
  14. <div id="form">
  15. <label>Nick: <input type="text" name="user" /></label><br />
  16. <br /><label>Password: <input type="password" name="password" /></label><br />
  17. <br /><label>Retype Password: <input type="password" name="repassword" /></label><br />
  18. <br /><label>E-mail: <input type="text" name="email" /></label><br />
  19. <br /><input type="submit" value="Send" /><br />
  20. </div>
  21. </form>
  22.  
  23. </body>
  24. </html>
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 10)
no_face
post
Post #2





Grupa: Zarejestrowani
Postów: 346
Pomógł: 23
Dołączył: 28.11.2004

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


zmien

  1. <?php
  2. $use= mysql_query ("SELECT user FROM base WHERE user='".$_POST['user']."' AND email='".$_POST['email']."'");
  3.  
  4. while ($check= mysql_fetch_assoc($use)) {
  5.  
  6. $chuser= $check['user'];
  7. $chmail= $check['email'];
  8.  
  9. }
  10. ?>


na

  1. <?php
  2. $use= mysql_query ("SELECT user, email FROM base WHERE user='".$_POST['user']."' AND email='".$_POST['email']."'");
  3.  
  4. $check= mysql_fetch_assoc($use))
  5.  
  6. $chuser= $check['user'];
  7. $chmail= $check['email'];
  8. ?>


Na szybko, ale powinno pomoc ;P
Go to the top of the page
+Quote Post
-Mefggt-
post
Post #3





Goście







Dalej to samo. Już nie wiem co jest nie tak (IMG:http://forum.php.pl/style_emoticons/default/tongue.gif) . Niby pokazuje że jak nie pasują hasła to nie rejestruje ale jak jest ten sam użytkownik a inny e-mail to mimo to rejestruje. Są jakieś inne lepsze sposoby na sprawdzenie użytkownika i maila ?
Go to the top of the page
+Quote Post
no_face
post
Post #4





Grupa: Zarejestrowani
Postów: 346
Pomógł: 23
Dołączył: 28.11.2004

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


No dobrze.

W przypadku jak chcesz sprawdzic i nicka i mejla musisz wykonac 2 osobne zapytania w poszukiwaniu tych informacji, gdyz oczywistym jest fakt, ze email moze wystapic przy innym nicku i na odwrot.

1. Sprawdzasz czy istnieje podany nick
2. Sprawdzasz czy istnieje podany email
3. Jezeli oba warunki sie nie spelniaja mozesz dokonac rejestracji.
Go to the top of the page
+Quote Post
-Mefggt-
post
Post #5





Goście







Czyli zrobić tak: Napisać ifa z mailem , drugiego ifa z userem ale jak to objąć jako jedną całość żeby dopiero po spełnieniu tych warunków rejestrowało?
Czy to zrobić wszystko w jednym ifie i połączyć dwie rzeczy tym && ?
Go to the top of the page
+Quote Post
piotrooo89
post
Post #6


Newsman


Grupa: Moderatorzy
Postów: 4 005
Pomógł: 548
Dołączył: 7.04.2008
Skąd: Trzebinia/Kraków




pierw sprawdź maila i nicka jak to przejdzie poprawnie to resztę rób... w przeciwnym razie wyświetl że wpisy już sie znajdują w bazie...
Go to the top of the page
+Quote Post
no_face
post
Post #7





Grupa: Zarejestrowani
Postów: 346
Pomógł: 23
Dołączył: 28.11.2004

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


Skorzystaj z funkcji mysql_num_rows($result), ktora zwroci Ci ilosc wynikow jakie zapytanie zwrocilo, w taki sposob dowiesz sie czy np nick istnieje w bazie, jezeli zwroci 0 oznacza to brak niku.
Go to the top of the page
+Quote Post
-Mefggt-
post
Post #8





Goście







OK spróbuję z mysql_num_rows($result) . Zaraz zobaczymy czy coś da. (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
-Mefggt-
post
Post #9





Goście







Zrobiłem coś takiego, ale dalej nic. Jak to w ogóle wykorzystać mysql_num_rows() ?

  1. <?php
  2.  
  3. mysql_connect ('localhost','root','mentormiszcz1e');
  4.  
  5. $nick= $_POST['user'];
  6. $password= $_POST['password'];
  7. $email= $_POST['email'];
  8. $repassword= $_POST['repassword'];
  9. $user= $nick;
  10. $mail= $email;
  11.  
  12. $use= mysql_query ("SELECT user FROM base WHERE user='".$_POST['user']."' AND email='".$_POST['email']."'");
  13.  
  14. $check= mysql_fetch_assoc($use);
  15. $chec= mysql_num_rows($use);
  16. $chuser= $check['user'];
  17. $chmail= $check['email'];
  18.  
  19. if (!empty($nick) && !empty($password) && !empty($email) && !empty($repassword)) {  // => Type all information
  20.  
  21.  
  22.  
  23. if ($user!= $chuser && $mail!= $chmail) {
  24.  
  25. $records= "INSERT INTO `base` (`user`, password, email) VALUES ('$nick','$password','$email');";
  26. mysql_query ($records);
  27.  
  28. echo 'You have been registered :)';
  29.  
  30. }
  31.  
  32. else {
  33.  
  34. echo 'This user already exists/ Typed password are not the same/E-mail is registered';
  35.  
  36. }
  37.  
  38.  
  39. } //end empty
  40.  
  41. else {
  42.  
  43. echo 'Type all information';
  44.  
  45. }
  46.  
  47. ?>
Go to the top of the page
+Quote Post
no_face
post
Post #10





Grupa: Zarejestrowani
Postów: 346
Pomógł: 23
Dołączył: 28.11.2004

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


  1. <?php
  2. $use= mysql_query ("SELECT user FROM base WHERE user='".trim($_POST['user']));
  3. $czy_user = mysql_fetch_assoc($use);
  4. $use= mysql_query ("SELECT user FROM base WHERE email='".trim($_POST['email']));
  5. $czy_email = mysql_fetch_assoc($use);
  6.  
  7. if ($czy_user < 1 && $czy_email < 1)
  8. {
  9.  nie ma takiego mejla i nicka w bazie, mozna rejestrowac
  10. }
  11. ?>


Funkcja trim usunie Ci zbedne puste znaki z konca i poczatku lini.

Ten post edytował no_face 25.05.2008, 13:42:36
Go to the top of the page
+Quote Post
-Mefggt-
post
Post #11





Goście







Nie no śmiga jak nic (IMG:http://forum.php.pl/style_emoticons/default/biggrin.gif) . Dzięki za pomoc (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 22.08.2025 - 13:09