btr4 Posted June 15, 2010 Share Posted June 15, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/204808-unexpected-t_string-error/ Share on other sites More sharing options...
trq Posted June 15, 2010 Share Posted June 15, 2010 $this->link = mysql_connect($host,$user,$pass); Quote Link to comment https://forums.phpfreaks.com/topic/204808-unexpected-t_string-error/#findComment-1072212 Share on other sites More sharing options...
btr4 Posted June 15, 2010 Author Share Posted June 15, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/204808-unexpected-t_string-error/#findComment-1072214 Share on other sites More sharing options...
kenrbnsn Posted June 15, 2010 Share Posted June 15, 2010 Remove the single quotes from this line: <?php $this->link mysql_connect('$host','$user','$pass'); ?> it should be <?php $this->link = mysql_connect($host,$user,$pass); ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/204808-unexpected-t_string-error/#findComment-1072215 Share on other sites More sharing options...
btr4 Posted June 15, 2010 Author Share Posted June 15, 2010 Hmmm, still receiving the same errors. Quote Link to comment https://forums.phpfreaks.com/topic/204808-unexpected-t_string-error/#findComment-1072217 Share on other sites More sharing options...
mrMarcus Posted June 15, 2010 Share Posted June 15, 2010 Are the db credentials correct? Quote Link to comment https://forums.phpfreaks.com/topic/204808-unexpected-t_string-error/#findComment-1072218 Share on other sites More sharing options...
btr4 Posted June 15, 2010 Author Share Posted June 15, 2010 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; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/204808-unexpected-t_string-error/#findComment-1072225 Share on other sites More sharing options...
mrMarcus Posted June 15, 2010 Share Posted June 15, 2010 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". Quote Link to comment https://forums.phpfreaks.com/topic/204808-unexpected-t_string-error/#findComment-1072228 Share on other sites More sharing options...
trq Posted June 15, 2010 Share Posted June 15, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/204808-unexpected-t_string-error/#findComment-1072237 Share on other sites More sharing options...
btr4 Posted June 16, 2010 Author Share Posted June 16, 2010 I removed the class settings like you suggested, went over the code, and it seemed a lot easier to get running. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/204808-unexpected-t_string-error/#findComment-1073165 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.