Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting "You have an error in your SQL syntax" error when submit php form
    primarykey
    data
    text
    <p>I'm creating a very simple php forum system to integrate with my portal system (I tried to integrate some existent ones, but all I've found have lots of features I don't want, so I decided to create my own). The page bellow is just a start point from the board creation page, but when I click on submit, I just get the following error: 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 'desc='Testing special characters á é ó ç ã ñ'' at line 1</p> <pre><code>&lt;?php function renderForm($nome, $desc, $error) { $nome = htmlspecialchars($_POST['nome']); $desc = htmlspecialchars($_POST['desc']); ?&gt; &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;New Record&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;?php if ($error != '') { echo '&lt;div style="padding:4px; border:1px solid red; color:red;"&gt;'.$error.'&lt;/div&gt;'; } ?&gt; &lt;form action="" method="post"&gt; &lt;div&gt; &lt;strong&gt;Nome: *&lt;/strong&gt; &lt;input type="text" name="nome" /&gt;&lt;br/&gt; &lt;strong&gt;Desc: *&lt;/strong&gt; &lt;input type="text" name="desc" /&gt;&lt;br/&gt; &lt;p&gt;* required&lt;/p&gt; &lt;input type="submit" name="submit" value="Submit"&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; &lt;?php } include("../../config.php"); if (isset($_POST['submit'])) { $nome = htmlspecialchars($_POST['nome']); $desc = htmlspecialchars($_POST['desc']); if ($nome == '' || $desc== '') { $error = 'ERROR: Please fill in all required fields!'; renderForm($nome, $desc, $error); } else { mysql_query("INSERT forum_boards SET nome='$nome', desc='$desc'") or die(mysql_error()); } } else { renderForm('','',''); } ?&gt; </code></pre> <p>What could be this?</p>
    singulars
    1. This table or related slice is empty.
    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.
    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