【问题标题】:SQL data insert to table errorSQL数据插入表错误
【发布时间】:2014-09-11 17:02:12
【问题描述】:

我正在尝试将复制图像插入文件夹并将图像路径保存到 SQL 表。我使用以下代码将图像存储在文件夹和数据库路径中。当我运行代码图像被复制但图像的路径没有存储在数据库中。

if(move_uploaded_file($temp_name, $target_path)) {
    $query_upload="INSERT into 'images_tbl' ('images_path','submission_date') VALUES('".$target_path."','".date("Y-m-d")."')";
    mysql_query($query_upload) or die("error in $query_upload == ----> ".mysql_error());  

当我运行它时,我得到以下错误

error in INSERT into 'images_tbl' ('images_path','submission_date') VALUES ('images/21-07-2014-1405927802.png','2014-07-21') == ----> 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 ''images_tbl' ('images_path','submission_date') VALUES ('images/21-07-2014-14' at line 1

【问题讨论】:

  • 尝试删除表和字段名称上的简单引号'

标签: php sql database image upload


【解决方案1】:

你的表名不应该有单引号,即它应该是:

INSERT INTO images_tbl ...

INSERT INTO `images_tbl` ... (note this uses backticks rather than single quotes)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多