Fatal error: Class 'database' not found - PHP
<p>When I attempt to use the problem class I get the following error:</p>

<pre><code>Fatal error: Class 'database' not found in path/problem.php on line 25
</code></pre>

<p>I don't understand why I got this error, at the top of problem.php I require database.php. What is happening?</p>

<p>problem.php</p>

<pre><code>&lt;?php
require("common.php");
require("database.php");

class problem
{
    // variable declaration
    protected $question;
    protected $answer;
    protected $tags;
    protected $problem_id;
    protected $commonStuff;
    protected $userID;
    protected $db;

    // parameters for $var = new problem(question, problem)
    function __construct($question_in="", $problem_in="") {
        $this-&gt;question = $question_in;
        $this-&gt;answer = $answer_in;
        $this-&gt;tags = array();
        $this-&gt;commonStuff = new common();
        $this-&gt;userID = $this-&gt;commonStuff-&gt;getUserID();
        $this-&gt;db = new database();

    }

    // set the question and answer
    function set_question($new_question) {
        $this-&gt;question = $new_question;
    }
    function set_answer($new_question) {
        $this-&gt;answer = $new_answer;
    }

    // get the question and answer
    function get_question() {
        return $this-&gt;question;
    }
    function get_answer() {
        return $this-&gt;answer;
    }
    function get_pid() {
        return $this-&gt;problem_id;
    }

    // add tag
    function add_tag($new_tag) {
        $this-&gt;tags[] = $new_tag;
        $this-&gt;tags     = array_unique($this-&gt;tags);
    }

    // check for errors
    function error_check_question() {
        if (empty($this-&gt;question))
            return true;
        else
            return false;       
    }
    function error_check_answer() {
        if (empty($this-&gt;answer))
            return true;
        else
            return false;   
    }

    // get ready to insert into database
    function code_parse($var) {

        // due math code processing
        preg_match_all("/(?&lt;=&lt;math&gt;)(.*?)(?=&lt;\/math&gt;)/", $var,$questionMath);
        foreach($questionMath[0] as $math) {
            $imgElement = "&lt;img src='http://chart.apis.google.com/chart?cht=tx&amp;chl=" . $commonStuff-&gt;mathToLatex($math) . "' /&gt;";
            $question = str_replace("&lt;math&gt;" . $math . "&lt;/math&gt;", $imgElement, $question);
        }

        $var = safe($var);

        return $var;
    }
    function safe($str) {
        return mysql_real_escape_string($str);
    }
    function build_insert_SQL() {
        $sql = "INSERT INTO problems (userid, question, answer, date, nextTimeToAnswer, correctStreak) VALUES(" . $this-&gt;userID . ", '" . code_parse($this-&gt;question) . "', '" . code_parse($this-&gt;answer) . "', '" . $this-&gt;date . "', '" . $this-&gt;date . "', 0)";     
        $this-&gt;problem_id = mysql_insert_id();
        return $sql;
    }
    // build the sql for tags
    function insert_tag_SQL() { 
        foreach($this-&gt;tags as $tag_val) {
            if (empty($tag_val) == false) {
                // check if the tag exists
                $result = $db-&gt;select_row("SELECT id FROM tags WHERE name = '$tag_val'");
                if (empty($result)) {
                    $db-&gt;execute("INSERT INTO tags (name) VALUES('$tag_val')");
                    $tagID = mysql_insert_id();
                }
                else {
                    $tagID = $result['id'];
                }
                // insert into tagmap
                $result = $db-&gt;select_row("SELECT tag_id FROM tagmap WHERE 
                 = " . $this-&gt;problem_id . " AND tag_id = $tagID");
                if (empty($result) == false) {
                    $sql = "INSERT INTO tagmap (problem_id,tag_id) VALUES($problem_id, $tagID)";
                    $db-&gt;execute($sql);
                }
            }
        }       
    }
    // insert the problem into the database
    function insert() {
        $sql = build_insert_SQL();
        $db-&gt;execute($sql);

        insert_tag_SQL();
    }
}
?&gt;
</code></pre>

<p>database.php</p>

<pre><code>&lt;?php
class database
{
    // variable declaration
    protected $host;
    protected $databaseUser;
    protected $databasePassword;
    protected $databaseName;
    protected $con;

    function __construct() {
        $this-&gt;host = "localhost";
        $this-&gt;databaseUser = "sambend1_sam";
        $this-&gt;databasePassword = "samjosh";
        $this-&gt;databaseName = "sambend1_brandon";
        $this-&gt;con = mysql_connect($host,$databaseUser,$databasePassword);
        return;
    }

    // select rows from database
    function select($query) {
        $result = mysql_query($query) or die ('This was an error: '.mysql_error ());
        return  $result;
    }

    // select an individual row and put it into a var
    function select_row($query) {
        $result = mysql_query($query) or die ('This was an error: '.mysql_error ());
        while($row = mysql_fetch_array($result)) {
            $toReturn = $row;
        }
        return  $toReturn;
    }

    // execute a query, such as insert or update
    function execute($query) {
        mysql_query($query) or die ('This was an error: '.mysql_error ());
    }
}

?&gt;
</code></pre>
