【发布时间】:2015-03-09 22:46:09
【问题描述】:
我正在尝试对数据库进行简单的插入,但找不到问题所在。如果有人可以提供帮助,那就太好了。我的代码:
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>";
}
领域方面:
<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">
错误:
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
【问题讨论】:
-
mysql_query is deprecated,考虑使用mysqli或更通用的PDO。您编写的代码容易受到SQL Injection Attack 的攻击,请查看bind parameters 以了解如何避免这种情况。