Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [MySQL][PHP]Błąd w PDO
o2w5n778
post
Post #1





Grupa: Zarejestrowani
Postów: 235
Pomógł: 0
Dołączył: 10.12.2009

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


Witam!
Mam pewnien problem z kodem. Ponieważ kod jest dość obszerny wyślę jedynie najpotrzebniejsze elementy.
index.php
  1. <?php
  2. $pdo = new PDO('mysql:host=localhost;dbname=manager', 'root', 'kokos', array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
  3. $pdo -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  4.  
  5. function getIndexTemplate(){
  6. if(file_exists('template/index.php')){
  7. require('template/index.php');
  8. } else {
  9. echo('The template/index.php file do not exists, You must create it!');
  10. }
  11. }
  12.  
  13. getIndexTemplate();
  14. ?>

template/index.php
  1. <?php
  2. if(isset($_SESSION['login'])){
  3. echo('Welcome');
  4. } else {
  5. require('login.php');
  6. }
  7. ?>

login.php
  1. <?php
  2. require('template/login.php');
  3. $login = $_POST['login'];
  4. $password = $_POST['password'];
  5. if(preg_match('/^[a-zA-Z0-9._-]{4,10}$/', $login) && preg_match('/^[a-zA-Z0-9!@#%&]{4,16}$/', $password)){
  6. $password = md5($password);
  7. $queryLogin = $pdo -> query("SELECT * FROM users");
  8. if($queryLogin->rowCount() == 1){
  9. $getUserDate = $queryLogin -> fetch();
  10. $_SESSION['zalogowany'] = array(
  11. 'user_login' => $getUserDate['user_login'],
  12. 'user_email' => $getUserDate['user_email'],
  13. 'user_last_login' => $getUserDate['user_last_login'],
  14. 'user_rank' => $getUserDate['user_rank']
  15. );
  16. }
  17. }
  18. ?>

Mój błąd to:
Cytat
Fatal error: Call to a member function query() on a non-object in /home/jakub/public_html/shell/login.php on line 7

W czym problem?

Ten post edytował o2w5n778 3.08.2012, 11:18:57
Go to the top of the page
+Quote Post
CuteOne
post
Post #2





Grupa: Zarejestrowani
Postów: 2 958
Pomógł: 574
Dołączył: 23.09.2008
Skąd: wiesz, że tu jestem?

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


Zmienne nie są globalne

  1. function getIndexTemplate($pdo){
  2. if(file_exists('template/index.php')){
  3. require('template/index.php');
  4. } else {
  5. echo('The template/index.php file do not exists, You must create it!');
  6. }
  7. }
  8.  
  9. getIndexTemplate($pdo);
Go to the top of the page
+Quote Post
Wazniak96
post
Post #3





Grupa: Zarejestrowani
Postów: 550
Pomógł: 75
Dołączył: 5.06.2012
Skąd: Lębork

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


Dodaj na początku funkcji
  1. extract($GLOBALS);
i powino byc ok.
Go to the top of the page
+Quote Post
CuteOne
post
Post #4





Grupa: Zarejestrowani
Postów: 2 958
Pomógł: 574
Dołączył: 23.09.2008
Skąd: wiesz, że tu jestem?

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


a za tym co wyżej jakiegoś evala do kolekcji
Go to the top of the page
+Quote Post
irmidjusz
post
Post #5





Grupa: Zarejestrowani
Postów: 279
Pomógł: 60
Dołączył: 25.02.2012

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


Cytat(CuteOne @ 3.08.2012, 12:53:30 ) *
a za tym co wyżej jakiegoś evala do kolekcji


+1 (IMG:style_emoticons/default/biggrin.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: 21.12.2025 - 08:05