Fatal error: Uncaught exception 'PDOException' with message

HI Folks,

This php error is killing me…

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 country=‘BGD’’ at line 4’ in /home4/xxx/public_html/visa/content/dashboard/pages/client_admin/visas/visa_alloc/allocate.php:188 Stack trace: #0 /home4/xxx/public_html/visa/content/dashboard/pages/client_admin/visas/visa_alloc/allocate.php(188): PDOStatement->execute(Array) #1 {main} thrown in /home4/xxx/public_html/visa/content/dashboard/pages/client_admin/visas/visa_alloc/allocate.php on line 188

$query = $db->prepare("SELECT * 
                       FROM visas");
$query->execute();
while($row = $query->fetch()) {
    $block_number=$row['block_number'];
    $pid=$row['position_id'];
    $cid=$row['country'];
    $number_of_visas=$row['number_of_visas'];
    
    
    if($number_of_visas==4){
       $query1 = $db->prepare("DELETE  
                               FROM visas
                               WHERE block_number=:block_number
                               AND position_id=:pid,
                               AND country=:cid");
       
       $query1->execute(array(':block_number' => $block_number,
                              ':pid' => $pid,
                              ':cid' => $cid));
    }
}
if($number_of_visas==4){
       $query1 = $db->prepare("DELETE  
                               FROM visas
                               WHERE block_number=:block_number
                               AND position_id=:pid,
                               AND country=:cid");

You have a comma after pid that shouldn’t be there, maybe try without that? I don’t recall if that would trip a syntax error or not.

1 Like

Thank you Jeff,
Amazing, it took more than one hour now. Thank you so much for your time. it works now !!!

1 Like

Sometimes all it takes is a pair of fresh eyes. Especially when dealing with pesky syntax problems, one can stare at it so long that one can’t even really see problems anymore! I know how that is.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.