Jump to content

Recommended Posts

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"

 

The code is as follows:

?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 of time for any assistance!

Link to comment
https://forums.phpfreaks.com/topic/204808-unexpected-t_string-error/
Share on other sites

Wow, can't believe I didn't catch that one. Feel like such an idiot. Thanks so much.

 

That fix has appeared to clear issue there, now I receive:

 

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'admin'@'localhost' (using password: YES) in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\linkexchangesystem\admin\dbconnector.php on line 21

 

Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\linkexchangesystem\admin\dbconnector.php on line 22

 

Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\linkexchangesystem\admin\dbconnector.php on line 22

 

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\linkexchangesystem\admin\dbconnector.php on line 30

Sorry, there was an error saving to the database

 

Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\linkexchangesystem\admin\dbconnector.php on line 42

 

From the same batch of code above.

 

Any clues?

Code for the systemcomponent.php file (password omitted)

<?php

class SystemComponent {
var $settings;

function getSettings() {
	/* System Variables */
	$settings['siteDir'] = '/../linkexchangesystem/';

	/* Database Variables */
	$settings['dbhost'] = 'localhost';
	$settings['dbusername'] = 'admin';
	$settings['dbpassword'] = 'bloop';
	$settings['dbname'] = 'dbhcc';

	return $settings;

}
}
?>

That's not what I was asking.  Is the username, password, database name correct?  "Access denied for user" usually means your db credentials are incorrect, or you have something amiss in your my.ini file.

 

Double check your user/pass/db name, and that the user "admin" has privileges on database "dbhcc".

Code for the systemcomponent.php file (password omitted)

<?php

class SystemComponent {
var $settings;

function getSettings() {
	/* System Variables */
	$settings['siteDir'] = '/../linkexchangesystem/';

	/* Database Variables */
	$settings['dbhost'] = 'localhost';
	$settings['dbusername'] = 'admin';
	$settings['dbpassword'] = 'bloop';
	$settings['dbname'] = 'dbhcc';

	return $settings;

}
}
?>

 

Your getSettings() method is not static. meaning it cannot be called using the :: syntax.

 

You really need to be developing with error_reporting set to E_ALL and display errors on. You might also want to give using classes a miss for a while because your not really adding any benefit to your programs design the way you are using them. In fact, until you have a greater understanding, I think they are the source of allot of your confusion.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.