Reputation: 1
I am trying to do a simple insert into database but cannot find where the problem is. If anyone could help would be great please. My code:
if(isset($_POST['s1']))
{
$q1 = "INSERT INTO tienda (title,desc) VALUES ('$title', '$desc')";
mysql_query($q1) or die(mysql_error());
echo "<div class=alert fade in><b>Group added!</b></div>";
}
The field side of things:
<tr>
<b>Titulo</b>
<input type=text name=title value="<?=$aset['title']?>" size=50> <br>
</tr>
<tr>
<b>Descripcion</b>
<input type=text name=desc value="<?=$aset['desc']?>" size=50> <br>
</tr>
</div>
</div>
<tr>
<td> </td>
<td>
<input type=submit name=s1 value=Upload class="btn btn-primary">
The error:
You have an error in your SQL syntax; check the manual that corresponds
to your MariaDB server version for the right syntax to use near 'desc)
VALUES (' Title ', '1')' at line 1
Upvotes: 0
Views: 84
Reputation: 44881
desc
is a reserved keyword in MySQL (short for description, used in the order by statement). Try enclosing that in backticks like
$q1 = "INSERT INTO tienda (title,`desc`) VALUES ('$title', '$desc')";
Upvotes: 3