unexpected T_STRING

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
btr4
Forum Newbie
Posts: 2
Joined: Mon Jun 14, 2010 9:42 pm

unexpected T_STRING

Post by btr4 »

Hi, I'm new to the forums, and to PHP itself. I'm designing a content management system through php, and am having quite a lot of fun with it. Alas, it seems as if I've hit a snag.

I can log into the system, but when I'm testing the "Add Staff" page, I receive this error:
"Parse error: syntax error, unexpected T_STRING in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\linkexchangesystem\admin\dbconnector.php on line 21"

Here's the code for the php file in question:

Code: Select all

?php

/* Class: DbConnector Purpose: Connect to the MySQL Database */
require_once('../admin/systemcomponent.php');
	$theQuery = 0;
	$link = 0;
class DbConnector {	
	/* Function: DbConnector, Purpose: Connect to the Database */
	function DbConnector(){
	
		/* Load settings from parent class */
		$settings = systemcomponent::getSettings();
		
		/* Get the main settings from the array */
		$host = $settings['dbhost'];
		$db = $settings['dbname'];
		$user = $settings['dbusername'];
		$pass = $settings['dbpassword'];
		
		/* Connect to the Database */
		$this->link mysql_connect('$host','$user','$pass');
		mysql_select_db($db);
		register_shutdown_function(array(&$this, 'close'));
		
	}

	/* Function: query, Purpose: Execute Database Query */
	function query($query) {
	$this->theQuery = $query;
	return mysql_query($query, $this->link);

	}
	
	/* Function: fetchArray, Purpose: Get array of query results */
	function fetchArray($result) {
		return mysql_fetch_array($result);
	
	}
	
	/* Function: close, Purpose: Close the connection */
	function close() {
		mysql_close($this->link);
		
		}
	
	}
}	
?>
Thanks ahead anytime for any assistance!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: unexpected T_STRING

Post by requinix »

Code: Select all

$this->link mysql_connect('$host','$user','$pass');
That's line 21. Anything seem wrong to you?

There's actually two things wrong. The first is a parse error and the second is putting variables inside quotes when they shouldn't be.

Also

Code: Select all

   $theQuery = 0;
   $link = 0;
class DbConnector {
Those variables are declared outside of the class. I'm pretty sure you want them inside.
Post Reply