Eggzorcist Posted May 7, 2011 Share Posted May 7, 2011 Hey, I'm wondering what the issue is, I'm new to using PDO and objects so I'm sure this is a common error but setting me on the right track would be greatly appreciated. Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND password = d41d8cd98f00b204e9800998ecf8427e' at line 1' in /Users/JPFoster/Sites/Jaipai.Blog/engine.php:47 Stack trace: #0 /Users/JPFoster/Sites/Jaipai.Blog/engine.php(47): PDO->query('SELECT * FROM u...') #1 /Users/JPFoster/Sites/Jaipai.Blog/index.php(7): SiteEngine->login('', '') #2 {main} thrown in /Users/JPFoster/Sites/Jaipai.Blog/engine.php on line 47 public function login($user, $pw){ $user = addslashes($this->user); $pw = md5($pw); $query = "SELECT * FROM users WHERE username = ".$user." AND password = ".$pw; //set up query $results = $this->pdo->query($query); $num_rows = $results->num_rows; if ($num_rows == 1){ $row = $results->fetch_assoc(); echo "Worked!"; //$this->set_session($row['id'], $row['username'], $row['email']); } else { echo "Your Username and Password did not match"; } //if user + passs match { redirect (member page) and set up sessions // Else ... Retry... } } I don't see an issue with my query, and the object is instantiated by having the submit button isset() and i use login($_post[user], $_post[pw]) Link to comment https://forums.phpfreaks.com/topic/235786-pdo-exception-and-object-problem/ Share on other sites More sharing options...
gristoi Posted May 7, 2011 Share Posted May 7, 2011 The exception is telling you that you have a syntax error in your query. This could be due to an escape character being passed into the user variable. Try doing: $query = "SELECT * FROM `users` WHERE `username` = '".$user."' AND `password` = '".$pw."'"; Also try and echo out $query to see what the query looks like Link to comment https://forums.phpfreaks.com/topic/235786-pdo-exception-and-object-problem/#findComment-1212007 Share on other sites More sharing options...
Eggzorcist Posted May 8, 2011 Author Share Posted May 8, 2011 That has helped a lot! Thanks, but now however, I have trouble with my PDO num_rows, is there a reason why its a fairly simplistic code so I'm not sure why it wouldn't work. Notice: Undefined property: PDOStatement::$num_rows in /Users/JPFoster/Sites/Jaipai.Blog/engine.php on line 48 Link to comment https://forums.phpfreaks.com/topic/235786-pdo-exception-and-object-problem/#findComment-1212363 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.