Solarpitch Posted July 24, 2008 Share Posted July 24, 2008 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 More sharing options...
DarkWater Posted July 24, 2008 Share Posted July 24, 2008 $query = "insert into {$this->dbUserTable} (id, username, account_name) values (NULL, \"$name\", \"$accountName\")"; Try that. And that's horrible OOP practice, by the way. >_> You've got way too much "stuff" going on in each class. Link to comment https://forums.phpfreaks.com/topic/116413-calling-a-class/#findComment-598631 Share on other sites More sharing options...
Solarpitch Posted July 24, 2008 Author Share Posted July 24, 2008 No joy with that im afraid ... I dont want start of learning OO with bad habits or practices as you said. Do you know of any decent sites or resources that offer good tutorials and that? Link to comment https://forums.phpfreaks.com/topic/116413-calling-a-class/#findComment-598649 Share on other sites More sharing options...
DarkWater Posted July 24, 2008 Share Posted July 24, 2008 There's a set of 3 tutorials on the main page of this site, actually. You're containing too much unrelated logic all in one class. In reality, does a client get delegated to connect to the database and handle queries? No. A database class does it. Link to comment https://forums.phpfreaks.com/topic/116413-calling-a-class/#findComment-598654 Share on other sites More sharing options...
Solarpitch Posted July 24, 2008 Author Share Posted July 24, 2008 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. Link to comment https://forums.phpfreaks.com/topic/116413-calling-a-class/#findComment-598662 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.