adrianle Posted June 18, 2015 Share Posted June 18, 2015 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(); } ? Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted June 19, 2015 Share Posted June 19, 2015 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.) Quote Link to comment Share on other sites More sharing options...
adrianle Posted June 22, 2015 Author Share Posted June 22, 2015 The solution was to change WA_DEFAULT to WA_IGNORE so that the field would be ignored in the update process if empty. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.