helloworld001 Posted February 6, 2015 Share Posted February 6, 2015 This should all be working but I think I might be overlooking something. Problem 1. I am using ajax to process a form. I don't think the problem is with ajax(works with other queries), but rather with php. Here is my simple query. $stmt = $db->prepare("SELECT * FROM records WHERE request_by = :request_by, request_to = :request_to AND session = :session"); $stmt->bindParam(':request_by', $byUserid); $stmt->bindParam(':request_to', $toUserid); $stmt->bindValue(':session', 1); $stmt->execute(); $result = $stmt->fetchAll(PDO::FETCH_ASSOC); if(count($result) > 0) { $success = 'This was successful.'; } else { $error = 'There was a problem.'; } This above query gives me this error. 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 ' request_to = '7' AND session = '1'' at line 1 Problem 2. Say the main page is "index.php" with submit form and I am using ajax via url: process.php. Well on "index.php" page, I have foreach loop that gets me a "$toUserid" for each record. I would like to use that "$toUserid" in "process.php" page. I tried setting it as a session but still it won't give me that exact userid. It'll give me the same userid as the user I am currently logged in. What exactly I am doing wrong and how I can i fix it? Quote Link to comment https://forums.phpfreaks.com/topic/294428-this-is-insane-i-need-fresh-pair-of-eyes-to-look-at-this-code-regarding-pdo-query-and-session/ Share on other sites More sharing options...
Solution Barand Posted February 6, 2015 Solution Share Posted February 6, 2015 The comma after :requestby should be an "AND". That's why it's telling you there is a syntax error there - read the message. Quote Link to comment https://forums.phpfreaks.com/topic/294428-this-is-insane-i-need-fresh-pair-of-eyes-to-look-at-this-code-regarding-pdo-query-and-session/#findComment-1505068 Share on other sites More sharing options...
helloworld001 Posted February 6, 2015 Author Share Posted February 6, 2015 The comma after :requestby should be an "AND". That's why it's telling you there is a syntax error there - read the message. Ah yes, that's it. I knew it was something small that I over looked. Quote Link to comment https://forums.phpfreaks.com/topic/294428-this-is-insane-i-need-fresh-pair-of-eyes-to-look-at-this-code-regarding-pdo-query-and-session/#findComment-1505101 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.