[UPHPU] OO Problem with basic classes

glen brown zyst at hotmail.com
Sun Dec 13 00:43:50 MST 2009


Hi All,

 

I have an method not an object of class in line 29 of the Register Class.

 

Anyone have any ideas how I can fix it?

 

Cheers,

 

Glen.

 

<?php

class DBSettings
{
 protected static $host = "";
 protected static $user = "";
 protected static $pass = "";
 protected static $db = "";
}

?>

<?php 
require_once("DBSettings.php");

class DB Extends DBSettings
{   
 private static $conn;

 public function connect()
 {
            DB::$conn = mysqli_connect(parent::$host, parent::$user, parent::$pass, parent::$db);
            echo "connecting";
            
            if (!DB::$conn)
            {
             echo "Not Connected";
            }
 }
 
 public function query($sql)
 {
  if (!DB::$conn)
  {
   DB::connect();
  }
  
     $result = mysqli_query(DB::$conn, $sql);
     
     if($result == FALSE) 
     {
      die("Error executing statement: " . htmlspecialchars( mysql_error() ) );
  exit;
     } else {
      return $result;
     }
 }
} 
?>

<?php 

require_once('DB.php');

class Register extends DB
{  

    function __constructor() 
    {
     parent::connect();
 } 

 function isValidEmail($email)
 {   
   return filter_var(filter_var($email, FILTER_SANITIZE_EMAIL), FILTER_VALIDATE_EMAIL);   
 } 
 
 function add($email)
 {
  // Confirm valid email address
  if (!Register::isValidEmail($email))
  {
   return 1;
  }
 
  // Check if the email address is already in the database
  $sql = "SELECT * FROM register WHERE email LIKE '" . $email . "'";
  
  $result = $this->query($sql);
  
  if ($result == False)
  {
   // Error running sql
   return 2;
  } else {
   if ($result->num_rows < 1)
   { 
    // Add the record as it does not exist
       $date = date('Y-m-d G:H:s');

       $sql = "INSERT INTO register(email, date) VALUES ('" . $email . "', '" . $date . "')";
  
       parent::query($sql);  
    
       return 3;
   }
  }
 }
 
 function delete($email)
 {
     $sql = "DELETE FROM register WHERE email LIKE '" . $email . "'";

     parent::query($sql);
 }

 function update($oldemail, $newemail)
 {
     $sql = "UPDATE register SET email = '" . $newemail . "' WHERE email = '" . $oldemail . "'";

     parent::query($sql);
 }
} 
?>   

 
 		 	   		  
_________________________________________________________________
Get more out of Hotmail Check out the latest features today
http://windowslive.ninemsn.com.au/hotmail/article/878466/your-hotmail-is-about-to-get-even-better


More information about the UPHPU mailing list