Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [mysql] problem z mysql - logowanie
sparky87
post
Post #1





Grupa: Zarejestrowani
Postów: 15
Pomógł: 0
Dołączył: 5.08.2006

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


Taki komunikat mi wyskakuje gdy właczam strone :

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /var/www/sites/yoyo.pl/f/c/fckublinie/login.php on line 34


A oto kod strony :

  1. <form action="login.php" method="post">
  2. <table border="0" width="580" align="center">
  3. <tr>
  4. <td width="180" align="right"> Uzytkownik :</td>
  5. <td width="400" align="left" colspan="2" > <input type="text" size="30" name="username"></td>
  6. </tr>
  7. <tr>
  8. <td width="180" align="right"> Haslo :</td>
  9. <td width="400" align="left" colspan="2" > <input type="text" size="30" name="password"></td>
  10. </tr>
  11. <tr>
  12. <td width="180" align="right"></td>
  13. <td width="145"></td>
  14. <td width="255"><input type="submit" name="submit" value="Login"></td>
  15. </tr>
  16. </form>


  1. <?php
  2.  
  3. if(isset($submit)){
  4. if (!$post["username"] or !$_post["password"]) {
  5. echo "Wprowadz nazwe uzytkownika i haslo !";
  6. }
  7. }
  8.  
  9.  
  10. $query = 'select * from user where name = $_post["username"]';
  11. $result = mysql_query($query);
  12. $row_count = mysql_num_rows($result);
  13. if ($row_count == 0) {
  14. echo "Wprowadz poprawna nazwe uzytkownika !";
  15. }
  16. else {
  17. $row = mysql_fetch_array($result);
  18. if ($_post["password"] == $row["pass"]) {
  19. echo "Logowanie zakonczylo sie sukcesem !";
  20. $SESSION["auth_username"] = $_post["username"];
  21. if ($row["level"] == 'superadmin') {
  22. header("Location: site1.php");}
  23. elseif ($row["level"] == 'admin') {
  24. header("Location: site2.php");}
  25. else {
  26. header("Location: site3.php");}
  27. }
  28. else {
  29. echo "Wpisz poprawne haslo !";
  30. }
  31. }
  32. ?>



Wie ktoś o co może chodzić? biggrin.gif Bede wdzieczny za wszelka pomoc biggrin.gif biggrin.gif To moj pierwszy skrypt tongue.gif

Ten post edytował sparky87 2.11.2006, 19:34:30
Go to the top of the page
+Quote Post
nospor
post
Post #2





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




  1. <?php
  2. $query = "select * from user where name = '$_POST[username]'";
  3. ?>

polecam lekture:
http://pl.php.net/manual/pl/language.types.string.php

proszę poprawić tytuł o znacznik zgodnie z zasadami forum Przedszkole:
Temat: Tematyka i zasady panujace na forum Przedszkole


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

"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
sparky87
post
Post #3





Grupa: Zarejestrowani
Postów: 15
Pomógł: 0
Dołączył: 5.08.2006

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


Dzieki za pomoc, ale niestety nic to nie dało tongue.gif ... ma moze ktos inny pomysl ? biggrin.gif oraz prosiłbym o ogólną ocenę kodu, chodz mi czy jest on poprawny w miare ? biggrin.gif
Go to the top of the page
+Quote Post
nospor
post
Post #4





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




to dopisz jeszcze:
  1. <?php
  2. $query = "select * from user where name = '$_POST[username]'";
  3. $result = mysql_query($query) or die('zap: '.$query.';;blad:'.mysql_error());
  4. ?>


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

"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
skowron-line
post
Post #5





Grupa: Zarejestrowani
Postów: 4 340
Pomógł: 542
Dołączył: 15.01.2006
Skąd: Olsztyn/Warszawa

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


  1. <?php
  2. if (!$post["username"] or !$_post["password"])
  3. ?>


a moze

  1. <?php
  2. if (!$_POST["username"] or !$_POST["password"])
  3. ?>


--------------------
I'm so fast that last night I turned off the light switch in my hotel room and was in bed before the room was dark - Muhammad Ali.
Peg jeżeli chcesz uprawiać sex to dzieci muszą wyjść, a jeżeli chcesz żeby był dobry ty też musisz wyjść - Al Bundy.

QueryBuilder, Mootools.net, bbcradio1::MistaJam
http://www.phpbench.com/
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 Aktualny czas: 21.08.2025 - 23:31