【问题标题】:how to save image name into database [closed]如何将图像名称保存到数据库中[关闭]
【发布时间】:2013-11-26 12:55:21
【问题描述】:

当我运行以下代码时,图像被移动到所需的文件夹,但没有任何内容保存在数据库中。如何将图像的名称保存在数据库中。请帮忙...

        mysqli_query($con,"INSERT INTO blog (title, image, content)
              VALUES ('$_POST[title]','$_POST[image]','$_POST[content]')");


    $target_Path = "uploaded/";
              $target_Path = $target_Path.basename( $_FILES['image']['name'] );
              move_uploaded_file( $_FILES['image']['tmp_name'], $target_Path );

【问题讨论】:

  • 不是真的,他想把那个图像放在那里。 ;)
  • ... 因为您没有包含该列的值?代码中倒数第二行引用图像名称。你为什么不尝试使用它?

标签: php mysql database image upload


【解决方案1】:

在您的查询中缺少图像值,试试这个:

mysqli_query($con,"INSERT INTO blog (title, image, content) 
VALUES ('$_POST[title]', '$_FILES[image][name]' ,'$_POST[content]')");

【讨论】:

  • 它与正在以 .bin 格式保存在数据库中的文件一起使用。帮助!
【解决方案2】:

您需要三个项目来匹配要插入数据的三列。

 mysqli_query($con,"INSERT INTO blog (title, image, content) VALUES ('$_POST[title]', '' ,'$_POST[content]')");

您还需要重新考虑将用户输入直接传递到数据库而不首先对其进行清理的策略。 http://en.wikipedia.org/wiki/SQL_injection

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-17
    • 2017-10-29
    • 1970-01-01
    • 1970-01-01
    • 2016-03-19
    • 1970-01-01
    • 2015-12-17
    • 2011-04-02
    相关资源
    最近更新 更多