Reputation: 4413
I'm going crazy looking for the error in the following PDO SELECT statement:
$get_allocation_id = "
SELECT id
FROM form1_group_info
WHERE
group_name=:group_name,
group_leaders=:group_leaders,
soas_short_cd=:soas_short_cd,
phone_number=:phone_number,
email=:email
LIMIT 1";
$alloc_id_stmt = $dbh->prepare($get_allocation_id);
$alloc_id_stmt->bindParam(":group_name", $params['group_name']);
$alloc_id_stmt->bindParam(":date_submitted", $params['date_submitted']);
$alloc_id_stmt->bindParam(":group_leaders", $params['group_leaders']);
$alloc_id_stmt->bindParam(":soas_short_cd", $params['soas_short_cd']);
$alloc_id_stmt->bindParam(":phone_number", $params['phone_number']);
$alloc_id_stmt->bindParam(":email", $params['email']);
$alloc_id_stmt->execute();
The above code is in a PHP file that is called by an ajax request which supplies $params.
Any suggestions are much appreciated.
Upvotes: 0
Views: 40
Reputation: 270617
Your SQL syntax is invalid; WHERE
clause conditions must separated by logical AND
(or OR
, but we assume you mean to sue AND
in this case), but you have separated them by commas:
SELECT id
FROM form1_group_info
WHERE
group_name=:group_name
/* Insert logical AND */
AND group_leaders=:group_leaders
AND soas_short_cd=:soas_short_cd
AND phone_number=:phone_number
AND email=:email
LIMIT 1;
As mentioned above, you are also binding a parameter which is not used in your query. Perhaps you mean:
SELECT id
FROM form1_group_info
WHERE
group_name=:group_name
AND group_leaders=:group_leaders
AND soas_short_cd=:soas_short_cd
AND phone_number=:phone_number
AND email=:email
/* forgot this one... */
AND date_submitted=:date_submitted
LIMIT 1;
Upvotes: 2
Reputation: 10732
It would help if you included the error. That said, I believe the problem is:
$alloc_id_stmt->bindParam(":date_submitted", $params['date_submitted']);
You're not using that parameter in your query.
Upvotes: 2