How to pass a variable to a class in another page
<p>I am trying to insert data into my database.I have three pages.First is <strong>index.php</strong> where i've the form.Second is <strong>db.php</strong> which holds the connection to databse.Third one is <strong>insert.php</strong> which holds insertion code.The problem that i'm facing is that when i make the <strong>insert</strong> class <strong><em>child</em></strong> of <strong><em>database</em></strong> class,It works fine but when i use <strong>insert</strong> class a separate class from <strong>database</strong> class.It's giving me an error.In short,i am unable to pass a variable which contains the database connection <strong>OBJECT</strong> to the <strong>insert</strong> class.</p>

<p><strong>index.php</strong></p>

<pre><code>&lt;?php

function __autoload($cl){

    require_once "classes_lib/$cl.php";

}

$database = new db();
if(isset($_POST['submit']))
{
     $name = $_POST['name'];
     $email = $_POST['email'];
     $ph = $_POST['phone'];

    try
    {
        $ins = new insert($database);
        echo $ins-&gt;insertUser($name, $email, $ph);

    }
    catch(PDOEXCEPTION $e)
    {
        echo $this-&gt;con_error . $e-&gt;getmessage();
    }
}
</code></pre>

<p><strong>classes_lib/db.php</strong></p>

<pre><code>&lt;?php

class db{

    public $con;
    public $con_error;

    public function connect(){

        try
        {
            $this-&gt;con = new PDO("mysql:host=localhost;dbname=oop","root","");
        }

        catch(PDOException $e)
        {
            echo $this-&gt;con_error = "An error in connecting to database" . $e-&gt;getmessage();
        }

    }

    public function __construct(){

        return $this-&gt;connect();

    }

}
</code></pre>

<p><strong>classes_lib/insert.php</strong></p>

<pre><code>&lt;?php

class insert{

    public $dbs;

    public function __construct($database){

        $this-&gt;dbs =  $database;
        return $this-&gt;dbs;

    }

    public function insertUser($name,$email,$ph){

        $stmt = $this-&gt;con-&gt;prepare("INSERT INTO `users` (`name`,`email`,`phone`) VALUES (:name,:email,:phone)");

        $stmt-&gt;bindParam(":name",$name);
        $stmt-&gt;bindParam(":email",$email);
        $stmt-&gt;bindParam(":phone",$ph);

        $stmt-&gt;execute();

    }

}
</code></pre>

<p>I'm so tired of the errors.Any help will be appreciated.</p>