【问题标题】:insert into database unknown error插入数据库未知错误
【发布时间】: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>&nbsp;</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 database mariadb


【解决方案1】:

desc 是 MySQL 中的 reserved keyword(描述的缩写,在 order by 语句中使用)。尝试将其括在反引号中,例如

$q1 = "INSERT INTO tienda (title,`desc`) VALUES ('$title', '$desc')";

【讨论】:

  • 是的,是reserved word。
  • 谢谢@jpw 你是对的。我将标记为答案正确。再次感谢!
猜你喜欢
  • 2023-04-11
  • 1970-01-01
  • 1970-01-01
  • 2017-08-17
  • 1970-01-01
  • 1970-01-01
  • 2018-07-08
  • 1970-01-01
  • 2011-10-09
相关资源
最近更新 更多