doushao8399 2013-05-14 20:13
浏览 31

将带有FILE和POST变量的bindValue导入SQL DB

I can't seem to get all of these variables to post to my database. It works when I leave out the $_POST of the $file_desc. All of the $_FILE variables pass through to my database. Here's the code for grabbing the variables:

$file_name = $_FILES['image']['name'];
$tmp = explode('.', $file_name);
$file_ext = strtolower(end($tmp));
$file_size = $_FILES['image']['size'];
$file_tmp = $_FILES['image']['tmp_name'];
$file_error = $_FILES['image']['error'];
$file_desc = nl2br($_POST['desc']);

And here's the code for running the query:

$query = $pdo->prepare('INSERT INTO upload (name, type, size, desc) VALUES (?, ?, ?, ?)');
$query->bindValue(1, $file_name);
$query->bindValue(2, $file_ext);
$query->bindValue(3, $file_size);
$query->bindValue(4, $file_desc);

$query->execute();
  • 写回答

1条回答 默认 最新

  • dongzhan1878 2013-05-14 20:15
    关注

    DESC is MySQL keyword, which is used to sort selected rows in descending order. In your case MySQL thinks it's keyword and not a field name. To make it understand that it's a field - you should put it in apostrophes:

    $query = $pdo->prepare('INSERT INTO upload (name, type, size, `desc`) VALUES (?, ?, ?, ?)');
    

    Also I would advice you to learn debugging and pay attention to errors returned: I bet MySQL told you something about "wrong syntax near desc at line 1".

    评论

报告相同问题?

悬赏问题

  • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
  • ¥15 unity连接Sqlserver
  • ¥15 图中这种约束条件lingo该怎么表示出来
  • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
  • ¥15 流式socket文件传输答疑
  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式
  • ¥50 关于多次提交POST数据后,无法获取到POST数据参数的问题
  • ¥15 win10,这种情况怎么办
  • ¥15 如何在配置使用Prettier的VSCode中通过Better Align插件来对齐等式?(相关搜索:格式化)
  • ¥100 在连接内网VPN时,如何同时保持互联网连接