nouaman Posted March 7, 2015 Share Posted March 7, 2015 please im seeking help through your helpful webite im using a code snipet from a website regarding user logon session so i got the error : Parse error: syntax error, unexpected '"', expecting ')' in your code on line 28 i check on php code checker and got the same error below is the code in question please point me to the error to be fixed as im unable to locate it even if im considering the error line and had a look at my code but eas unable to resolve this issue also i found in google somethingn related to php version but im not sur so FYI im using version 5.4,16 ofo PHP thank you in advance code : ------------------------------------------ /* Snippet #1 */ <?php // login_check.php define("server", "localhost"); define("user", "root"); define("password", ""); define("name", "test"); $connection; $this->connection = mysql_connect(localhost,root,'') or die(mysql_error()); mysql_select_db(name, $this->connection) or die(mysql_error()); function is_logged_in () { if (!($_SESSION["id"]) || ($_SESSION["id"] == "") || ($_SESSION["id"] == 0)) { Header("Location: ./login.php"); exit(); } } function clean_input($input) { $clean = array("",'<','>','`',':',';','/','(',')','{','}','[',']'); //$with = array(); return str_ireplace($clean,'', $input); } function login_check ($forms) { $error = ""; $username = clean_input($forms["username"]); $password = clean_input($forms["password"]); if (trim($username) == "") $error .= "<li>Your username is empty.</li>"; if (trim($password) == "") $error .= "<li>Your password is empty.</li>"; /* from here, do your sql query to query the database to search for existing record with correct username and password */ $query = "SELECT password, username FROM users WHERE username = '".mysql_real_escape_string($username)."' AND password = '".mysql_real_escape_string($password)."'"; $result = mysql_query($query, $this->connection); if(!$result || (mysql_numrows($result) < 1)) { $error = "Invalid username or password"; }else { $error = ""; } if (trim($error)!="") return $error; } function login ($forms) { $username = clean_input($forms["username"]); $password = clean_input($forms["password"]); /* do your sql query again, but now returning the id of member */ $query = "SELECT member_id FROM users WHERE username = '".mysql_real_escape_string($username)."' AND password = '".mysql_real_escape_string($password)."'"; $result = mysql_query($query, $this->connection); $result = mysql_query($query, $this->connection); if(!$result || (mysql_numrows($result) < 1)) { $id = 0; }else { $id = $result; } return $id; } ?> Link to comment Share on other sites More sharing options...
Ingolme Posted March 7, 2015 Share Posted March 7, 2015 On this line you have an escaped double-quote: $clean = array("",'<','>','`',':',';','/','(',')','{','}','[',']'); If you need to put a backslash in a string you need to escape it with another backslash: $clean = array("",'<','>','`',':',';','/','(',')','{','}','[',']'); Link to comment Share on other sites More sharing options...
nouaman Posted March 7, 2015 Author Share Posted March 7, 2015 Hi there thank you for your reply it was helpful fixing that problem but now i got another error related to this line : $this->connection = mysql_connect('localhost','root','') or die(mysql_error()); and the error was :Fatal error: Using $this when not in object context in C:wampwwwphploginsnipetlogin_check.php on line 10 any suggestion would be appreciated thanks in advance Link to comment Share on other sites More sharing options...
Ingolme Posted March 7, 2015 Share Posted March 7, 2015 Why are you using $this? It's a reserved variable for use within class methods. Link to comment Share on other sites More sharing options...
nouaman Posted March 7, 2015 Author Share Posted March 7, 2015 hi there thanks for your reply first , actually as i mentioned in my first post i m using this code snipet so i copied/pasted the code to see if it s working and then try to customized for my need so i got stack with these errors.so. i guess that the code snipet should not use it as you mentioned in this case could you please suggest me what to use instead or point me to what can be done and i will dig on it on my own that will be very appreciated thanks again for taking time to read my posts Note : im beginer in PHP so when im stack on something i use google to find out solution or this site w3schools or hints from this forum Link to comment Share on other sites More sharing options...
Don E Posted March 7, 2015 Share Posted March 7, 2015 Just to note, mysql is depreciated, use mysqli instead or PDO. Link to comment Share on other sites More sharing options...
Ingolme Posted March 7, 2015 Share Posted March 7, 2015 You should read the W3Schools tutorial: http://www.w3schools.com/php/php_mysql_connect.asp It does you no good to copy code without knowing what it does. Link to comment Share on other sites More sharing options...
nouaman Posted March 7, 2015 Author Share Posted March 7, 2015 i ll give it a shot thanks so much i will post my reply later to let u know if i did solve this issue thanks again Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now