Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] PDO - błąd składni
troian
post 7.09.2015, 08:40:03
Post #1





Grupa: Zarejestrowani
Postów: 184
Pomógł: 2
Dołączył: 3.02.2013

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


Witam, zakładam iż moja funkcja posiada jakiś błąd jednak nie bardzo wiem gdzie popełniłem błąd i dlaczego nie działa:
  1. $connect=new PDO('mysql:host='.host.';port='.port, user, pass, array( PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8'));
  2. if(isset($_POST['START']))
  3. {
  4. $query = $connect->prepare("SELECT * FORM account.account WHERE login = ? AND password = PASSWORD(?) LIMIT 1");
  5. $result = $query->execute(array($_POST['login'], $_POST['pass'])) ? $query->fetch() : false;
  6. if($result)
  7. {
  8. echo 'jest user';
  9. }else{
  10. echo 'nie ma usera';
  11. }
  12. }


Czy ktoś może widzi błąd ?
Efekt błędu, zawartość $result jest pusta
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 10)
kapslokk
post 7.09.2015, 08:53:38
Post #2





Grupa: Zarejestrowani
Postów: 965
Pomógł: 285
Dołączył: 19.06.2015
Skąd: Warszawa

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


FORM
Go to the top of the page
+Quote Post
Pyton_000
post 7.09.2015, 08:54:13
Post #3





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


po $result

  1. $arr = $query->errorInfo();
  2. print_r($arr);
Go to the top of the page
+Quote Post
troian
post 7.09.2015, 09:01:19
Post #4





Grupa: Zarejestrowani
Postów: 184
Pomógł: 2
Dołączył: 3.02.2013

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


To błąd podczas przepisywania kodu, oto oryginalny kod:
  1. public function start_login()
  2. {
  3. global $mysql, $massage_login;
  4. $connect = $mysql->connect();
  5. $massage_login = array();
  6. $table = Array(1 => 'id',2 => 'login',3 => 'email',4 => 'cash',5 => 'social_id',6 => 'silver_expire');
  7.  
  8. if((test_char($_POST['login']) && test_char($_POST['pass'])) && !empty($_POST['login']) && !empty($_POST['pass']))
  9. {
  10. $login = clear($_POST['login']);
  11. $pass = clear($_POST['pass']);
  12. $query = $connect->prepare("SELECT id,login,email,cash,social_id,silver_expire FROM ".account.".account WHERE login='?' AND password=password('?') LIMIT 1");
  13. $result = $query->execute(array($login,$pass)) ? $query->fetch() : false;
  14. if($result)
  15. {
  16. for( $x = 1; $x <= count($table); $x++ )
  17. {
  18. $_SESSION[$table[$x]] = $result[$table[$x]];
  19. }
  20. $_SESSION['time_login'] = strtotime(date("Y-m-d H:i:s"))+60*15;
  21. $massage_login[2] = '<meta http-equiv="Refresh" content="0; url='.url().'/konto" />';
  22. }else{
  23. $massage_login[1] = 'login-incorrect_data_account';
  24. }
  25. }else{
  26. $massage_login[1] = 'login-null_incorrect_data';
  27. }


po dodaniu print_r mam taki wynik : Array ( [0] => 00000 [1] => [2] => )

Ten post edytował troian 7.09.2015, 09:04:40
Go to the top of the page
+Quote Post
kapslokk
post 7.09.2015, 09:06:17
Post #5





Grupa: Zarejestrowani
Postów: 965
Pomógł: 285
Dołączył: 19.06.2015
Skąd: Warszawa

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


  1. FROM ".account.".account


Czemu w ten sposób? Trzymasz nazwę tabeli w jakiejś stałej? Wrzuć to co podał Pyton i sprawdź błędy.
Go to the top of the page
+Quote Post
troian
post 7.09.2015, 09:11:02
Post #6





Grupa: Zarejestrowani
Postów: 184
Pomógł: 2
Dołączył: 3.02.2013

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


Cytat(kapslokk @ 7.09.2015, 10:06:17 ) *
  1. FROM ".account.".account


Czemu w ten sposób? Trzymasz nazwę tabeli w jakiejś stałej? Wrzuć to co podał Pyton i sprawdź błędy.


Wynik: Array ( [0] => 00000 [1] => [2] => )

tamto jest to definicja i jest prawidłowa gdyż przy poprzednim kodzie działało wszystko prawidłowo.
Go to the top of the page
+Quote Post
viking
post 7.09.2015, 09:13:14
Post #7





Grupa: Zarejestrowani
Postów: 6 380
Pomógł: 1116
Dołączył: 30.08.2006

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


Spróbuj sobie też wyświetlić http://fi2.php.net/manual/en/class.pdostat...ops.querystring z PDOStatement. Nie pamiętam już ale jaki był efekt kiedy dodawało się `?` wokół bindowanych parametrów?


--------------------
Go to the top of the page
+Quote Post
troian
post 7.09.2015, 09:23:43
Post #8





Grupa: Zarejestrowani
Postów: 184
Pomógł: 2
Dołączył: 3.02.2013

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


Jedyne co otrzymuje to : Array ( [0] => 00000 [1] => [2] => ) albo nulla
Go to the top of the page
+Quote Post
Pyton_000
post 7.09.2015, 09:28:41
Post #9





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


nie '?' a ?
Go to the top of the page
+Quote Post
troian
post 7.09.2015, 09:31:02
Post #10





Grupa: Zarejestrowani
Postów: 184
Pomógł: 2
Dołączył: 3.02.2013

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


Cytat(Pyton_000 @ 7.09.2015, 10:28:41 ) *
nie '?' a ?


o.O Danke smile.gif
Go to the top of the page
+Quote Post
Pyton_000
post 7.09.2015, 09:43:59
Post #11





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


Ja wolę Zośkę tongue.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 Wersja Lo-Fi Aktualny czas: 14.08.2025 - 03:24