0

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.

3
  • Add your insert code too.
    – Sumesh TG
    Commented Jul 13, 2018 at 7:38
  • The insert code is not the problem. I am inserting it via PDO which works if I'm not using the multipart.
    – Jake
    Commented Jul 13, 2018 at 8:03
  • 1
    @Jake — You need to provide a minimal reproducible example. It is unlikely that people will be able to identify a solution just by seeing a piece of code that triggers the issue in isolation and without the other code it interacts with.
    – Quentin
    Commented Jul 13, 2018 at 8:30

1 Answer 1

0

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.