[SOLVED] Parse Error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
partiallynothing
Forum Commoner
Posts: 61
Joined: Fri Nov 21, 2003 5:02 pm
Location: connecticut, usa

[SOLVED] Parse Error

Post by partiallynothing »

I have a short script that is somehow generating a parse error...

Code: Select all

<?php

/*DATABASE CLASS--------------------------------------------------------------*/

class database {

  protected $db_user;
  protected $db_pass;
  protected $db_host;
  protected $db_name;
  protected $dbh;

  public function __construct ($db_user, $db_pass, $db_host, $db_name) {
    $this->db_user = $db_user;
    $this->db_pass = $db_pass;
    $this->db_host = $db_host;
    $this->db_name = $db_name;
  }

  protected function connect() {
    try {
      $this->dbh = mysql_pconnect ($this->db_host, $this->db_user, $this->db_pass);
      if (!is_resource($this->dbh)) {
        throw new error (__CLASS__, 
                         __FUNCTION__, 
                         'database connection not a valid resource');
      }
    }
    catch (error $e) {
      echo '<p>Error in '.$e->getclass.'::'.$e->getfunction.': '.$e->getmsg.'</p>';
      $e->senderror();
    }
    try {
      if (!mysql_select_db($this->db_name, $this->dbh)) {
        throw new error (__CLASS__,
                         __FUNCTION__,
                         'could not select database');
      }
    }
    catch (error $e) {
      echo '<p>Error in '.$e->getclass.'::'.$e->getfunction.': '.$e->getmsg.'</p>';
      $e->senderror();
    }
  }

  public function execute($query) {
    if (!$this->dbh) {
      $this->connect();
    }
    $result = mysql_query($query, $this->dbh);
    try {
      if (!$result) {
        throw new error (__CLASS__, 
                         __FUNCTION__, 
                         'could not query database');
      }
      else if (!is_resource($result)) {
        throw new error (__CLASS__, 
                         __FUNCTION__, 
                         'database result is not a valid resource');
      } else {
        return $result;
      }
    }
    catch (error $e) {
      echo '<p>Error in '.$e->getclass.'::'.$e->getfunction.': '.$e->getmsg.'</p>';
      $e->senderror();
    }
  }

  public function get_row($result) {
    return mysql_fetcg_row($result);
  }

  public function get_assoc($result) {
    return mysql_fetch_assoc($result);
  }

  public function get_array($result) {
    return mysql_fetch_array($result);
  }

}

/*ERROR CLASS-----------------------------------------------------------------*/

class error extends Exception {

  protected $error_class;
  protected $error_function;
  protected $error_msg;

  public function __construct ($error_class, $error_function, $error_msg) {
    $this->error_class = $error_class;
    $this->error_function = $error_function;
    $this->error_msg = $error_msg;
  }

  public getclass () {
    return $this->error_class;
  }

  public getfunction () {
    return $this->error_function;
  }

  public getmsg () {
    return $this->error_msg;
  }

  public senderror () {
    $to  = 'openhelpadmin@sbcglobal.net';
    $subject = 'Error in '.$this->getclass.'::'.$this->getfunction.': '.$this->getmsg.'.';
    $message = '<html>
                <head>
                 <style type="text/ass">
                 body {
                      text-align:center;
                      font-family:sans-serif;
                      }
                 </style>
                </head>
                <body>
                 <p>Error in '.$this->getclass.'::'.$this->getfunction.': '.$this->getmsg.'.</p>
                </body>
                </html>';
    $headers  = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $headers .= "From: OpenHelp <no-reply@openhelp.org>\r\n";
    mail($to, $subject, $message, $headers);
  }

}
?>
The parse error I get is:

Code: Select all

Parse error: parse error, unexpected T_STRING, expecting T_VARIABLE in /www/openhelp.org/beta/lib_classes.php on line 108
To save you from counting, line 108 is:

Code: Select all

<?php
  public getclass () { 
?>
The file that is using the classes and calling the function is index.php. The following is that page:

Code: Select all

<?php

/*INCLUDE FILES---------------------------------------------------------------*/

require_once('conf_vars.php');
require_once('lib_classes.php');

/*DEFINE CURRENT PAGE---------------------------------------------------------*/

if (!$_GET['page']) {
  $page_current = 'main';
} else {
  $page_current = strip_tags(htmlspecialchars($_GET['page']));
}

/*MAKE PAGE-------------------------------------------------------------------*/

$database = new database($_CONFIG['db_user'],
                         $_CONFIG['db_pass'],
                         $_CONFIG['db_host'],
                         $_CONFIG['db_name']);


$database->execute('thiswillnotwork');
?>
Any help would be great! Thanks!
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Code: Select all

public getclass () { 
    return $this->error_class; 
  } 

  public getfunction () { 
    return $this->error_function; 
  } 

  public getmsg () { 
    return $this->error_msg; 
  } 

  public senderror () {
Are these not functions???? :P

(i.e. your missing "function" from them all)
User avatar
partiallynothing
Forum Commoner
Posts: 61
Joined: Fri Nov 21, 2003 5:02 pm
Location: connecticut, usa

Thanks

Post by partiallynothing »

Thanks! I can't believe I missed that. Sucks being on a team of one; always good to have others looking at your code when you eyes become to swolen to differenciate letters :p. Thanks again!
Post Reply