Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [mysql] mysql_num_rows():
Babcia@Stefa
post 17.09.2006, 11:39:38
Post #1





Grupa: Zarejestrowani
Postów: 654
Pomógł: 17
Dołączył: 19.03.2006
Skąd: z kosmosu ;)

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


Witam, mam jakiś błąd z funkcją mysql_num_rows , i niewiem dlaczego takowy jest, tabele są utworzone wszystko działa oprócz tej jednej funkcji która jest mi bardzo potrzebna (inaczej użytkownicy by się rejestrowali jeden na drugiego, kasując innego)

Oto błąd:

Cytat(Błąd)
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/accounts_b/babciastefa/public_html/otg/register.php on line 50



A oto kod:

  1. <?php
  2. elseif(mysql_num_rows($query)==1)
  3.  {
  4.  print "$userexist[$lang]";
  5.  }
  6. ?>



Jeśli ktoś chce większy fragment kodu lub cały plik to moge wklejić bo niejest aż taki wielki smile.gif

@edit

A to jest zapytanie do funkcji mysql_num_rows:

  1. $query=mysql_query("SELECT * FROM users WHERE u_name='$_POST[userName]' ");



@edit
Cytat(Błąd)
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/accounts_b/babciastefa/public_html/otg/register.php on line 34
Gratulacje Tedunio, zarejestrowałeś się poprawnie!
Za chwilę na twoją skrzynkę e-mail (babciastefa1231k@o2.pl) przyjdzie list z kodem aktywacyjnym, jeśli takowy niedojdzie skontaktuj się z administratorem strony.


A zmieniłem kod na taki jak jest na dole (bogdan89)

Dziękuję, Babcia@Stefa

Ten post edytował Babcia@Stefa 17.09.2006, 13:36:41


--------------------
Środowisko testowe (desktop) - Gedit, lighttpd, sftp, rsync, xfce4-terminal, chromium, firefox4 | System: Gentoo ~x86
O'Neill - serwer WWW @ lighttpd, links, nano, rsyncd, sftpd | System: Debian
Go to the top of the page
+Quote Post
bogdan89
post 17.09.2006, 11:51:52
Post #2





Grupa: Zarejestrowani
Postów: 320
Pomógł: 36
Dołączył: 28.08.2006
Skąd: Wrocław

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


więc ja bym to zrobił w ten sposób winksmiley.jpg

  1. <?php
  2. $userName = $_POST[userName];
  3.  
  4. $ile = mysql_num_rows(mysql_query("SELECT * FROM users WHERE u_name='$userName'"));
  5.  
  6. if ($ile > 0) {
  7. echo 'jest już taki login';
  8. } else {
  9. echo 'można rejestrować';
  10. }
  11. ?>
Go to the top of the page
+Quote Post
b0b3k
post 17.09.2006, 11:56:17
Post #3





Grupa: Zarejestrowani
Postów: 26
Pomógł: 0
Dołączył: 24.08.2006

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


jezeli masz sprawdzic tylko czy jest taki login zajęty to po co pobierać "*" (wszystko) ? styknie tylko login winksmiley.jpg
Go to the top of the page
+Quote Post
Babcia@Stefa
post 17.09.2006, 13:21:29
Post #4





Grupa: Zarejestrowani
Postów: 654
Pomógł: 17
Dołączył: 19.03.2006
Skąd: z kosmosu ;)

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


Jak coś to dam cały kod:

  1. <script type="text/javascript">
  2. <!-- <![CDATA[
  3. function regulamin()
  4. {
  5. if(document.getElementById('license_box').checked == true )
  6. {
  7. document.getElementById('next_box').disabled=false;
  8. }
  9. else
  10. {
  11. document.getElementById('next_box').disabled=true;}
  12. }
  13. // ]]> -->
  14. </script>
  15. <?php
  16. polacz();
  17. echo "<title>$sitetitle -=$register[$lang]=-</title>";
  18. $pagename = "$register[$lang]";
  19. ?>
  20. <?php if($koniecrejestracji == "0") { echo "<form action="index.php?p=register&lang=$lang" method="post">";?>
  21. <input type="hidden" name="regEnd" value="true">
  22. <?php echo "$user[$lang]";?>: <input type="text" name="userName" maxlength="32"><br>
  23. <?php echo "$pass[$lang]";?>: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="userPasswd1" maxlength="8"><br>
  24. <?php echo "$pass1[$lang]";?>: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="userPasswd2" maxlength="8"><br>
  25. <?php echo "$email[$lang]";?>: &nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="userEmail" maxlength="32"><br>
  26. <?php echo "$accrules[$lang]";?><input type="checkbox" id="license_box" onclick="regulamin()" /><br>
  27. <input type="submit" name="ok" value="Zarejestruj" id="next_box" disabled="disabled">
  28. </form>
  29. <?php
  30. }
  31. if($_POST["regEnd"]=="true")
  32. {
  33.  $query=mysql_query("SELECT * FROM users WHERE u_name='$_POST[userName]' ");
  34.  $ile = mysql_num_rows(mysql_query("SELECT * FROM users WHERE u_name='$userName'"));
  35.  
  36.  if(!$_POST["userName"] OR !$_POST["userPasswd1"] OR !$_POST["userPasswd2"] OR !$_POST["userEmail"])
  37.  {
  38.  print "$pola[$lang]";
  39.  }
  40.  elseif($_POST["userPasswd1"]!=$_POST["userPasswd2"])
  41.  {
  42.  print "$fhasla[$lang]";
  43.  }
  44.  elseif(!eregi("^[_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,4}$",$_POST["userEmail"]))
  45.  {
  46.  print "$femail[$lang]";
  47.  }
  48.  elseif(strlen($_POST["userName"])<4 OR strlen($_POST["userPasswd1"])<4)
  49.  {
  50.  print "$fnh[$lang]";
  51.  }
  52.  
  53.  elseif($ile > 0)
  54.  {
  55.  print "$userexist[$lang]";
  56.  }
  57.  else
  58.  {
  59.  $_POST["userPasswd1"]=SHA1($_POST["userPasswd1"]);
  60.  $actCode=str_shuffle("qwertyuiopasdfghjklzxcvbnm1234567890");
  61.  $headers="MIME-Version: 1.0rn";
  62.  $headers.="Content-type: text/html; charset=iso-8859-2rn";
  63.  $content="<html><head><title>Aktywacja konta w $sitetitle</title></head>
  64. <body>
  65. $aktywacja[$lang]
  66. </body></html>";
  67. mail($_POST["userEmail"], "Link Aktywacyjny", $content, $headers);
  68.  mysql_query("INSERT INTO users (u_name, u_password, u_email, u_activation_key) VALUES('$_POST[userName]', '$_POST[userPasswd1]', '$_POST[userEmail]', '$actCode')");
  69. print "$regisucces[$lang]";
  70. }
  71. }
  72. elseif($_GET["active"])
  73. {
  74.  mysql_query("UPDATE users SET u_active=1 WHERE u_activation_key='$_GET[active]' ");
  75. {
  76.  print"$activated[$lang]";
  77.  }
  78.  else
  79.  {
  80. print"$nactive[$lang]";
  81. }
  82. }
  83.  
  84. ?>


@edit
W tabeli jest klucz główny pod id.

@edit

Oto zapytanie z jakiego utworzyłem tabele:

  1. CREATE TABLE users (
  2. u_id int(11) NOT NULL AUTO_INCREMENT,
  3. u_name varchar(32) NOT NULL DEFAULT '',
  4. u_password varchar(40) NOT NULL DEFAULT '',
  5. u_email varchar(64) NOT NULL DEFAULT '',
  6. u_activation_key varchar(40) NOT NULL DEFAULT '',
  7. u_active int(1) NOT NULL DEFAULT '0',
  8. PRIMARY KEY (u_id)
  9. ) ENGINE=MyISAM DEFAULT CHARSET=latin2;


Ten post edytował Babcia@Stefa 17.09.2006, 14:14:19


--------------------
Środowisko testowe (desktop) - Gedit, lighttpd, sftp, rsync, xfce4-terminal, chromium, firefox4 | System: Gentoo ~x86
O'Neill - serwer WWW @ lighttpd, links, nano, rsyncd, sftpd | System: Debian
Go to the top of the page
+Quote Post
gszesiek
post 17.09.2006, 13:45:10
Post #5





Grupa: Zarejestrowani
Postów: 152
Pomógł: 1
Dołączył: 17.09.2006

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


nie przeczytałem dokładnie -> rozwiązanie, które podał bogdan89 winksmiley.jpg u mnie śmiga i post b0b3k'a (czy może b0bka) smile.gif

Ten post edytował gszesiek 17.09.2006, 14:31:40


--------------------
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: 14.08.2025 - 07:23