Jump to content

File fields and mySQLi?


adrianle

Recommended Posts

I'm using some PHP file upload code that I've used without problems with old mySQL.  When I use this same functionality with mySQLi and upload a new file, the filename INSERTs into the DB just fine with the value from the "file" field.

 

When I try to UPDATE the same record however, all other text fields update fine, but the "file" type field winds up clearing that column for that record. Almost like the field (which has been set to take the equivelent value from a recordset) is ignored, or not populated, or something.  Does anyone know if there's an issue with "file" type fields and mySQLi? I wouldn't think so.. here's my Update code:

<?php
if (isset($_POST["button"]) || isset($_POST["button_x"])) {
  $UpdateQuery = new WA_MySQLi_Query($Conn);
  $UpdateQuery->Action = "update";
  $UpdateQuery->Table = "TableName";
  $UpdateQuery->bindColumn("FileName", "s", "".((isset($_FILES["fileField"]))?$_FILES["fileField"]["name"]:"")  ."", "WA_DEFAULT");
  $UpdateQuery->addFilter("DocID", "=", "i", "".($_GET['DocID'])  ."");
  $UpdateQuery->execute();
}
?
Link to comment
Share on other sites

have you done any debugging to make sure that the $_FILES data is what you expect?

 

also, there are at least three problems with what you are showing use in that code -

 

1) you should validate that input data exists and is what you expect before using that data. your code should never get to the point of running a query unless you know you should be running that query.

 

2) isset($_FILES["fileField"]) that $_FILES element will be set, even if there is no valid uploaded file. if a user doesn't select a file and likely for some of the possible upload errors, what you are testing in the isset() statement can be true, but the ['name'] element that you are using can be empty. this is actually related to the above item. you shouldn't be testing for data at the point of using it in a query. by the time you get to the point of forming and running the query, you should have already determined if there's data present.

 

3) "all other text fields update fine". unless you removed lines of code from what you posted, that implies you are repeating similar code for each field and are running a separate query for each field. that is a database killer. you should update all the fields using one query (note: if none of the values being updated have changed, mysql doesn't actually update the record.)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.