Jump to content

Calling a class?


Solarpitch

Recommended Posts

Hi,

 

I'm starting to develop code using classes and I just set up this small test class to add something to a table, when the class is called I just get a blank HTML screen meaning there is an error somewhere. I tried using error_reporting(E_ALL) but still got no heads up.

 

Here's the class

 

<?php

class client {


    var $name,
        $accountName,
	$dbUserTable;

    function client() {
        $this->dbHost = 'localhost';
        $this->dbUser = 'xxxxxx';
        $this->dbName = 'xxxxxx';
        $this->dbPass = 'xxxxxx';
        $this->dbUserTable = 'xxxxxx';
    }
    
    function insertClient($name, $accountName) {

        $dbLink = mysql_connect($this->dbHost, $this->dbUser, $this->dbPass);
        if(!$dbLink) die("Could not connect to database. " . mysql_error());


        mysql_select_db($this->dbName);

        $query = "insert into $this->dbUserTable (id, username, account_name) values (NULL, \"$name\", \"$accountName\")";
        $result = mysql_query($query);
        

        if(!$result) die("Query didn't work. " . mysql_error());


        $this->userID = mysql_insert_id();


        mysql_close($dbLink);


        $this->userName = $userName;
        $this->userPassword = $userPassword;
    } 

}

?>

 

Then on the submission pages I have..

 

<?php

include("params/client.php");

$process = $_POST['process'];
if($process != "execute")
{
	//Do noting...
}
else
{
	//Process form...

	$name = $_POST['name'];
	$account_name = $_POST['account'];

                /code breaks here...

	$myClient = new client;
	$myClient->insertClient($name, $accountName);

}

?>

 

My Syntax seems fine and my version of PHP is 5 so I'm a little lost

Link to comment
https://forums.phpfreaks.com/topic/116413-calling-a-class/
Share on other sites

Yeah I see what you mean, I was thinking that but asked... how would I create a database class then use that class when I need to connect to the database while calling a new instance of the client class  :) .. I guess I got put off by that logic.

 

I think I'll look at a few of the tutorials on this site before I go any further.  8)

Link to comment
https://forums.phpfreaks.com/topic/116413-calling-a-class/#findComment-598662
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.