anix Posted May 6, 2008 Share Posted May 6, 2008 Hi all i am fairly new to using PHp and creating my own code however i am trying to install a script on my site and i get this message when i go to my home page to set everythink up "Parse error: syntax error, unexpected ';', expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/sgcrys5/public_html/include/sql.inc.php on line 1" i have no idea were the error is in the code i have looked for a "," that is out of place and cannot spot 1 the full code is listed bellow, i hope someone can help me with this. thanks. <?php class sql { var $mysql_type = 1; var$sql_server_type= 2; var$db_type = 1; //mysql function sql( $db_type ) { $this->db_type = $db_type; } function connection( $dm_name, $db_name, $db_username, $db_password, &$err ) { if ( $this->db_type == $this->mysql_type ) { $db = mysql_connect($dm_name, $db_username, $db_password ); if ( $db != FALSE ) { if ( !@mysql_select_db($db_name,$db) ) { $err = "select database error: " . mysql_error(); return FALSE; } } else { $err = "mysql_connect error: " . mysql_error(); return FALSE; } } else { $err = "not supported"; return FALSE; } return $db; } function sql_query($sql, $db, &$err) { if ( $this->db_type == $this->mysql_type ) { $res = @mysql_query($sql, $db); if ( !$res ) { $err = mysql_error(); return FALSE; } return $res; } } function sql_next_row(&$res ) { if ( $this->db_type == $this->mysql_type ) { return mysql_fetch_row($res); } } function sql_num_row($res) { if ( $this->db_type == $this->mysql_type ) { return @mysql_num_rows($res); } } function sql_close($db) { if ( $this->db_type == $this->mysql_type ) { @mysql_close($db); } } function sql_free_result($res) { if ( $this->db_type == $this->mysql_type ) { @mysql_free_result($res); } } function sql_field_name($res,$index) { if ( $this->db_type == $this->mysql_type ) { return @mysql_field_name($res,$index); } } function sql_insert_id($res) { if ( $this->db_type == $this->mysql_type ) { return mysql_insert_id($res); } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/104414-parse-error-syntax-error-unexpected/ Share on other sites More sharing options...
Caesar Posted May 6, 2008 Share Posted May 6, 2008 I'm guessing an extra/missing curly bracket. What line does the error say it's in? P.S - It be easier to find if you indented properly. Quote Link to comment https://forums.phpfreaks.com/topic/104414-parse-error-syntax-error-unexpected/#findComment-534520 Share on other sites More sharing options...
wildteen88 Posted May 6, 2008 Share Posted May 6, 2008 There error is coming from /home/sgcrys5/public_html/include/sql.inc.php on line 1. Is the code you posted above from sql.inc.php Quote Link to comment https://forums.phpfreaks.com/topic/104414-parse-error-syntax-error-unexpected/#findComment-534522 Share on other sites More sharing options...
Caesar Posted May 6, 2008 Share Posted May 6, 2008 There error is coming from /home/sgcrys5/public_html/include/sql.inc.php on line 1. Is the code you posted above from sql.inc.php True dat. Quote Link to comment https://forums.phpfreaks.com/topic/104414-parse-error-syntax-error-unexpected/#findComment-534525 Share on other sites More sharing options...
wildteen88 Posted May 6, 2008 Share Posted May 6, 2008 Just tested the code you posted with PHP and no errors where reported. Your script could do with some indentation so the code becomes more readable function my_func( --params-- ) { if( --condition-- ) { // your code } } Rather than: function my_func( --params-- ) { if( --condition-- ) { // your code } } Quote Link to comment https://forums.phpfreaks.com/topic/104414-parse-error-syntax-error-unexpected/#findComment-534535 Share on other sites More sharing options...
anix Posted May 6, 2008 Author Share Posted May 6, 2008 i have also tested this code on my local server at home using windows and it runs fine but when i run it on my linux webserver i get these errors and dont know why, i asked the service provider to see if they knew but they just blame the code so im stuck, can any one help with this, i appreciate the fast replies so far thanks. Quote Link to comment https://forums.phpfreaks.com/topic/104414-parse-error-syntax-error-unexpected/#findComment-534538 Share on other sites More sharing options...
wildteen88 Posted May 6, 2008 Share Posted May 6, 2008 Make sure you are saving the file in the correct encoding. I suggested ANSI (or ASCII). if you are saving it as UTF-8 make sure you save the file as UTF-8 without BOM. Quote Link to comment https://forums.phpfreaks.com/topic/104414-parse-error-syntax-error-unexpected/#findComment-534546 Share on other sites More sharing options...
anix Posted May 6, 2008 Author Share Posted May 6, 2008 thanks for all the help for the moment it seems that now i have indented the file correclty it has skipped that error and moved onto another one in another file so im presuming that for some reason it doesn't like the lack of indentation within each of the files so i will have to go through and indent them all as i go lol, this will no doubt take me some time but it needs to be done to ensure that everything runs ok, i just cant understand why on windows it runs without error!, thanks for all the help so far and i will keep you updated on my progress incase i need more assistance this forum is quite excellent thanks. Quote Link to comment https://forums.phpfreaks.com/topic/104414-parse-error-syntax-error-unexpected/#findComment-534554 Share on other sites More sharing options...
Caesar Posted May 7, 2008 Share Posted May 7, 2008 Windows sucks. They're all about ignoring standards :-P (Doubt the indentation alone was the issue though. Could be some garbage/unseen blank characters were in the files due to the way they were saved/transfered on your Windows box. Again, Windows blows gonads.) Quote Link to comment https://forums.phpfreaks.com/topic/104414-parse-error-syntax-error-unexpected/#findComment-535339 Share on other sites More sharing options...
wildteen88 Posted May 7, 2008 Share Posted May 7, 2008 Umm. How have you come to that conclusion! PHP is cross platform independent. It could be any number of things which was causing the error. Quote Link to comment https://forums.phpfreaks.com/topic/104414-parse-error-syntax-error-unexpected/#findComment-535346 Share on other sites More sharing options...
revraz Posted May 7, 2008 Share Posted May 7, 2008 It doesn't care if it's indented or not, it's skipped regardless. More than likely there are hidden chars somewhere. Have you tried looking at the files with Notepad? Quote Link to comment https://forums.phpfreaks.com/topic/104414-parse-error-syntax-error-unexpected/#findComment-535387 Share on other sites More sharing options...
Caesar Posted May 7, 2008 Share Posted May 7, 2008 Umm. How have you come to that conclusion! PHP is cross platform independent. It could be any number of things which was causing the error. Oh I'm sure the error was not an issue with the server OS...my opinion of PHP running on Windows is the same though. Especially with IIS. Quote Link to comment https://forums.phpfreaks.com/topic/104414-parse-error-syntax-error-unexpected/#findComment-535614 Share on other sites More sharing options...
benphp Posted May 7, 2008 Share Posted May 7, 2008 Could be how you set up your error reporting in php.ini. Here's your script: <?php class sql { var $mysql_type = 1; var$sql_server_type= 2; var$db_type = 1; //mysql function sql( $db_type ) { $this->db_type = $db_type; } function connection( $dm_name, $db_name, $db_username, $db_password, &$err ) { if ( $this->db_type == $this->mysql_type ) { $db = mysql_connect($dm_name, $db_username, $db_password ); } if ( $db != FALSE ) { if ( !@mysql_select_db($db_name,$db) ) { $err = "select database error: " . mysql_error(); return FALSE; } else { $err = "mysql_connect error: " . mysql_error(); return FALSE; } } else { $err = "not supported"; return FALSE; } return $db; } //function function sql_query($sql, $db, &$err) { if ( $this->db_type == $this->mysql_type ) { $res = @mysql_query($sql, $db); if ( !$res ) { $err = mysql_error(); return FALSE; } return $res; } } function sql_next_row(&$res ) { if ( $this->db_type == $this->mysql_type ) { return mysql_fetch_row($res); } } function sql_num_row($res) { if ( $this->db_type == $this->mysql_type ) { return @mysql_num_rows($res); } } function sql_close($db) { if ( $this->db_type == $this->mysql_type ) { @mysql_close($db); } } function sql_free_result($res) { if ( $this->db_type == $this->mysql_type ) { @mysql_free_result($res); } } function sql_field_name($res,$index) { if ( $this->db_type == $this->mysql_type ) { return @mysql_field_name($res,$index); } } function sql_insert_id($res) { if ( $this->db_type == $this->mysql_type ) { return mysql_insert_id($res); } } } //class ?> Quote Link to comment https://forums.phpfreaks.com/topic/104414-parse-error-syntax-error-unexpected/#findComment-535633 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.