Jump to content

This is insane. I need fresh pair of eyes to look at this code regarding pdo query and session.


helloworld001
Go to solution Solved by Barand,

Recommended Posts

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.