Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [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

Posty w temacie


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: 23.12.2025 - 18:40