doubang4881 2018-07-13 07:30
浏览 66

在MySQL插入上使用multipart / form-data的奇怪行为

I have a form like this

<form method="post" enctype="multipart/form-data">
    <input type="text" name="field01">
    <input type="file" name="file01">
    <button type="submit" name="update">Update</button>
    <button type="submit" name="new">Save New</button>
</form>

It contains different input fields like in the example above.

Now I am experiencing a strange behaviour. I added the enctype later after testing my MySQL Inserts / Updates etc. That works as expected. The file upload works as well, but now I have the problem, that my INSERTs does not work anymore using the multipart/form-data. Strangely my UPDATEs does work together with my image uploads. If I remove the enctype, my INSERTs do work, but my file uploads obviously not.

My POST Data is also correct in both (INSERT / UPDATE) cases, also the PDO Statement (checked it using queryString). As I said, it works.

How button type="submit" are handled with this type of form? I already tried input type="submit" to check if that's the problem, but the result is the same.

  • 写回答

1条回答 默认 最新

  • doupu9251 2018-07-13 08:48
    关注

    ok, I figured it out. The problem was not the multipart, it was that I was saving the filename of the images in the database. But if multipart is activated, the content is binary (even if no file is set). That caused the problem and the INSERT failed.

    I suppose UPDATE ignores fields which cannot be updated and leaves them empty?

    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数