2011-04-02 103 views
0

即時得到這個錯誤:PHP腳本錯誤

Fatal error: Call to a member function query() on a non-object in C:\EasyPHP-5.3.6.0\www\Database Manager\install\registration.php on line 18 

繼承人我的代碼:

<?php 
include("../sql_information.php"); 

class infos { 

    private $sql_initialize; 

    function login_details() { 

     $sql_initialize = new MySQLDatabase(); 
     $sql_initialize; 
     user_name='$register_user_name'"; 
     $queryresult = $this->sql_initialize->query($sql); 


     if ($sql_initialize->fetchArray($queryresult)) { 
      $errors[] = "Username already taken"; 
     } 

     if ($register_password !== $confirm_password) { 
      $errors[] = "Passwords mismatch"; 
     } 

     if (!$errors) { 
      //$register_password = mysql_real_escape_string($register_password); 
      $sql = "INSERT INTO `data_manager`.`user_accounts` (`id`, `user_name`, `password`) VALUES (NULL, '$register_user_name', '$register_password')"; 
      mysql_query($sql); 
      print "registered !"; 
      //header("Location: complete.php"); 
      exit; 
     } else { 
      foreach ($errors as $err) echo $err; 
     } 
    } 
} 
?> 

回答

1
$sql_initialize = new MySQLDatabase(); 

... 

$queryresult = $this->sql_initialize->query($sql); 

你可能會嘗試在$this->sql_initialize那裏,不$sql_initialize創建對象。

+0

謝謝你現在就工作! – 2011-04-02 23:59:23

3

login_details的第一行,你設置的局部變量$sql_initialize。您需要改爲設置$this->sql_initialize

0

最可能的是MySQLDatabase由於錯誤而沒有返回對象,可能在MySQLDatabase類中!

+0

我想你是在影響$ sql_initialize變量。你有兩個$ sql_initialize變量。一個是login_details()函數的本地,另一個屬於該類。 – Nabeel 2011-04-03 00:43:00

+0

替換此行: $ sql_initialize = new MySQLDatabase(); By this one $ this-> sql_initialize = new MySQLDatabase(); – Nabeel 2011-04-03 00:43:58