Note that there are some explanatory texts on larger screens.

plurals
  1. POSQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax — PHP — PDO
    primarykey
    data
    text
    <p>I've looked through all the other stackoverflow (and google) posts with the same problem, but none seemed to address my problem.</p> <p>I am using pdo and php.</p> <p>My code:</p> <pre><code>$vals = array( ':from'=&gt;$email, ':to'=&gt;$recipient, ':name'=&gt;$name, ':subject'=&gt;$subject, ':message'=&gt;$message ); print_r($vals); try { $pdo = new PDOConfig(); $pdo-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "SELECT * FROM messages WHERE `message` LIKE :message"; $q = $pdo-&gt;prepare($sql); $q-&gt;execute(array(':message' =&gt; $vals[':message'])); $resp = $q-&gt;fetchAll(); foreach ($resp as $row) { throw new Exception('Please do not post the same message twice!'); } $sql = "INSERT INTO messages (from, to, name, subject, message) VALUES (:from, :to, :name, :subject, :message)"; $q = $pdo-&gt;prepare($sql); $q-&gt;execute($vals); } catch(PDOException $e) { echo $e-&gt;getMessage(); } </code></pre> <p>and the first print_r gives</p> <pre><code>Array ( [:from] =&gt; abc@gmail.com [:to] =&gt; lala@me.com [:name] =&gt; abc [:subject] =&gt; abc [:message] =&gt; abc ) </code></pre> <p>which is expected (none are null)</p> <p>but it outputs the error</p> <blockquote> <p>QLSTATE[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 'from, to, name, subject, message) VALUES ('abc@gmail.com', 'lala@me.com' at line 1</p> </blockquote> <p>No idea how to fix this... ideas?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload