Hi all,
I have been throwing together something and I have come back to using PDO for the first time in a while (dont ask) and when I am running a prepared statement I am being thrown an error I have never seen before, a quick bit of Google-fu has come up with nothing useful for me so I was hoping that you wonderful bunch can help, below is the statement and full error:
$stmt = $db->prepare('INSERT INTO obs VALUES (:store, :tgt, :ob, now(), :q1, :q2, :q3, :q4, :q5, :q6, :q7, :q8, :q9, :q10,
:q11, :q12, :q13, :q14, :q15, :q16, :q17, :q18, :q19, :q20, :q21, :q22, :q23, :q24, :q25, :q26, :score)');
$stmt->execute(array(
':ob' => $sub['observer'],
':tgt' => $sub['observed'],
':score' => $count,
':store' => $sub['store'],
':q1' => (isset($sub['welcome1']) ? 1 : 0),
':q2' => (isset($sub['welcome2']) ? 1 : 0),
':q3' => (isset($sub['welcome3']) ? 1 : 0),
':q4' => (isset($sub['welcome4']) ? 1 : 0),
':q5' => (isset($sub['welcome5']) ? 1 : 0),
':q6' => (isset($sub['hand1']) ? $sub['hand1'] : 0),
':q7' => (isset($sub['under1']) ? 1 : 0),
':q8' => (isset($sub['under2']) ? $sub['under2'] : 0),
':q9' => (isset($sub['under3']) ? 1 : 0),
':q10' => (isset($sub['under4']) ? 1 : 0),
':q11' => (isset($sub['under5']) ? 1 : 0),
':q12' => (isset($sub['under6']) ? 1 : 0),
':q13' => (isset($sub['under7']) ? 1 : 0),
':q14' => (isset($sub['guide1']) ? 1 : 0),
':q15' => (isset($sub['guide2']) ? 1 : 0),
':q16' => (isset($sub['guide3']) ? 1 : 0),
':q17' => (isset($sub['guide4']) ? 1 : 0),
':q18' => (isset($sub['guide5']) ? 1 : 0),
':q19' => (isset($sub['guide6']) ? 1 : 0),
':q20' => (isset($sub['guide7']) ? 1 : 0),
':q21' => (isset($sub['guide8']) ? 1 : 0),
':q22' => (isset($sub['easy1']) ? $sub['easy1'] : 0),
':q23' => (isset($sub['easy2']) ? 1 : 0),
':q24' => (isset($sub['fare1']) ? 1 : 0),
':q25' => (isset($sub['fare2']) ? 1 : 0),
':q26' => (isset($sub['fare3']) ? 1 : 0)
));
The error I receive is:
PDOException: 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 ‘)’ at line 2 in C:\wamp\www\obs\index.php on line 79
Line 79 is the closing parenthesis at the end of the snippet. The reason for all the ternary checks is that I am working with checkboxes for input and obviously if they have not been ticked then they do not appear so I need to make sure that there is at least a 0 value in there.