Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]PDO + Ajax - problem z pobraniem wartości GET lub POST
casperii
post 12.02.2017, 21:48:37
Post #1





Grupa: Zarejestrowani
Postów: 681
Pomógł: 28
Dołączył: 14.08.2014

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


Panowie mam kod:
pobieram poprzez ajax metodą GET login z pola email o nazwie "admin"

  1. $res = $pdo->prepare('SELECT id, user, email, pass FROM users WHERE `user`=:login LIMIT 1');
  2. $res->bindValue(':login', $_GET['email'], PDO::PARAM_STR);
  3. //$res->bindValue(':pass', md5($_GET['pass']), PDO::PARAM_STR);
  4. $res->execute();
  5. $cos = $res->fetch();
  6.  
  7.  
  8. if($cos['id']>0){
  9. $msg = 'Zalogowano użytkownika '. $_GET['email'];
  10. }else{
  11. $msg = 'W bazie nie ma takiego użytkownika '. $_GET['email'];
  12. }


Powyższy kod podaje mi że w bazie nie ma użytkownika admin.

Jeżeli wstawię sobie na sztywno w zapytanie user = 'admin' to jest wszystko w porządku. Więc co tu jest zgrane ? smile.gif
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 6)
trueblue
post 12.02.2017, 22:19:51
Post #2





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


Pod $_GET['email'] jest login/user czy email?


--------------------
Go to the top of the page
+Quote Post
casperii
post 12.02.2017, 22:28:59
Post #3





Grupa: Zarejestrowani
Postów: 681
Pomógł: 28
Dołączył: 14.08.2014

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


w bazie pole user, w kodzie input name email (tu założenie dla tego inputa jest albo wpisujemy login albo email) - później to sobie zrobię w zapytaniu user = $_GET['email'] or email = $_GET['email'] - obecnie login to pole w bazie user pobierane z input name email.

Nawet jak zrobię w ten sposób to też nic :

  1. $res = $pdo->prepare('SELECT id, user, email, pass FROM users WHERE `user`=:user LIMIT 1');
  2. $res->bindValue(':user', $_GET['email'], PDO::PARAM_STR);


Ten post edytował casperii 12.02.2017, 22:32:17
Go to the top of the page
+Quote Post
trueblue
post 12.02.2017, 22:32:52
Post #4





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


var_dump($_GET['email']);

co daje?


--------------------
Go to the top of the page
+Quote Post
casperii
post 12.02.2017, 22:34:40
Post #5





Grupa: Zarejestrowani
Postów: 681
Pomógł: 28
Dołączył: 14.08.2014

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


string(5) "admin" null
Go to the top of the page
+Quote Post
nospor
post 12.02.2017, 22:58:09
Post #6





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




A ten null to skad ci sie wzial? Zdaje sie mialej tylko jeden var_dump()


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

"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
casperii
post 13.02.2017, 19:52:51
Post #7





Grupa: Zarejestrowani
Postów: 681
Pomógł: 28
Dołączył: 14.08.2014

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


dobra null był z tego powodu:

  1. echo json_encode($msg);


Ale w dalszym ciągu nie rozwiązało to mojego problemu. Dlaczego wyrzuca że nie znaleziona usera w bazie?
var_dump wyświetla: string(5) "admin"

Ten post edytował casperii 13.02.2017, 20:06:35
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 - 12:19