timothyarden Posted January 20, 2013 Share Posted January 20, 2013 (edited) Hi Everyone, This should just be a quick fix but I can't find what I have done wrong - Parse error: syntax error, unexpected '$error' (T_VARIABLE) in... on line 30. Here is the code class database_action { function __construct($value, $ssl = false){ $mysql_credentials = array('host' => "localhost", 'database_username' => "root", 'database_password' => "", 'database_name' => "test", 'table_name' => "test"); // New MySQLi Connection Object if(isset($ssl) && $ssl == true){ $mysqli = new mysqli("https://".$mysql_credentials['host'],$mysql_credentials['database_username'],$mysql_credentials['database_password'],$mysql_credentials['database_name']); } else { $mysqli = new mysqli($mysql_credentials['host'],$mysql_credentials['database_username'],$mysql_credentials['database_password'],$mysql_credentials['database_name']); } // Check for MySQLi Error if($mysqli -> connect_error()){ exit('MySQL Connection Error: ('.$mysqli -> connect_errno().')'.$mysqli -> connect_error()); $error = $mysqli -> connect_errno().' - '.$mysqli -> connect_error(); } // MySQLi Query $sql_statement = $mysqli -> stmt_init(); if($sql_statement = $mysqli -> prepare('INSERT INTO test VALUES(`?`)')){ $sql_statement -> bind_param('s',$value); $sql_statement -> execute(); if(isset($sql_statement -> $error) || isset($sql_statement -> $errno)){ $sql_error = $sql_statement -> $errno.' - '.$sql_statement -> $error; } $sql_statement -> close(); } else { $sql_error = $sql_statement -> $errno.' - '.$sql_statement -> $error; } $mysqli -> close(); // Return $errors or $sql_error if set otherwise return success if(isset($this -> $error)){ return $this -> $error; } elseif(isset($this -> $sql_error)){ return $this -> $sql_$error } else { return true; } } } Thanks, Timothy $value = 'test'; new database_action($value); Edited January 20, 2013 by timothyarden Quote Link to comment https://forums.phpfreaks.com/topic/273370-parse-error-syntax-error-unexpected-error-t_variable-in-on-line-30/ Share on other sites More sharing options...
Jessica Posted January 20, 2013 Share Posted January 20, 2013 Can you even read your own code? Cause I sure cant. Quote Link to comment https://forums.phpfreaks.com/topic/273370-parse-error-syntax-error-unexpected-error-t_variable-in-on-line-30/#findComment-1407003 Share on other sites More sharing options...
timothyarden Posted January 20, 2013 Author Share Posted January 20, 2013 Thanks for the reply. Yes I can, its just in my editor - Notepad ++ it is all indented. However when I copy across the clip-boarded code it is all un-indented. If I then try to indent it in the editor here on phpfreaks when I post it it it shows up as - which is even worse. Figured out the problem before though - and so marked it solved. Timothy Quote Link to comment https://forums.phpfreaks.com/topic/273370-parse-error-syntax-error-unexpected-error-t_variable-in-on-line-30/#findComment-1407004 Share on other sites More sharing options...
Jessica Posted January 20, 2013 Share Posted January 20, 2013 Cool. In the future hit the little toggle in the top left and just type without the spaces Quote Link to comment https://forums.phpfreaks.com/topic/273370-parse-error-syntax-error-unexpected-error-t_variable-in-on-line-30/#findComment-1407005 Share on other sites More sharing options...
timothyarden Posted January 20, 2013 Author Share Posted January 20, 2013 Trying what you said if($database_result == true){ echo "Success"; } else { echo "Error: ".$database_result; } Quote Link to comment https://forums.phpfreaks.com/topic/273370-parse-error-syntax-error-unexpected-error-t_variable-in-on-line-30/#findComment-1407007 Share on other sites More sharing options...
timothyarden Posted January 20, 2013 Author Share Posted January 20, 2013 Didn't work perfectly but better than before I guess... Thankyou Quote Link to comment https://forums.phpfreaks.com/topic/273370-parse-error-syntax-error-unexpected-error-t_variable-in-on-line-30/#findComment-1407008 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.