Pure PHP Upload 3 Support Product Page

Answered

File upload filename not retained when updating table

Asked 19 Mar 2014 12:03:04
1
has this question
19 Mar 2014 12:03:04 David Woolley posted:
I know this issue has been reported before in another post, but no resolution yet.
Pure PHP Upload 3.02 with DW CS6.
Update Record does not retain the filename of the uploaded file if another field in the table is updated. Insert Record works fine.

I've been trying to resolve this myself for days now but coming up against a brick wall! Endless permutations!
Filename always gets overwritten by NULL in the table.
I'm restricting file extension to zip as I will use the ZIP Processor PHP 3 after I've sorted this issue. Here is the code with the input statement included as well. No redirect yet while I troubleshoot this page.

<?php require_once('../ScriptLibrary/incPureUpload.php'); ?>
<?php 
//*** Pure PHP File Upload 3.0.1
// Process form form1
$ppu = new pureFileUpload();
$ppu->nameConflict = "uniq";
$ppu->storeType = "file";
$ppu->progressBar = "vista_look.htm";
$ppu->progressWidth = 300;
$ppu->progressHeight = 100;
$ppu->path = "../presentations_vm";
$ppu->allowedExtensions = "zip"; // "custom"
$ppu->redirectUrl = "";
$ppu->checkVersion("3.0.1");
$ppu->doUpload();
?>
<?php
// Cancel button before UPDATE RECORD - DGW
if (array_key_exists('Cancel', $_POST)) {
	header('Location: admin.php');
	exit;
}
?>
<?php
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE cases SET category_id=%s, museum_no=%s, case_no=%s, other_ref_no=%s, snomed=%s, icd10=%s, title=%s, patientdata=%s, grosspathology=%s, histology=%s, `comment`=%s, presentation=%s, web_url=%s, anat_diag=%s, `references`=%s WHERE case_id=%s",
                       GetSQLValueString($_POST['category_id'], "int"),
                       GetSQLValueString($_POST['museum_no'], "text"),
                       GetSQLValueString($_POST['case_no'], "text"),
                       GetSQLValueString($_POST['other_ref_no'], "text"),
                       GetSQLValueString($_POST['snomed'], "text"),
                       GetSQLValueString($_POST['icd10'], "text"),
                       GetSQLValueString($_POST['title'], "text"),
                       GetSQLValueString($_POST['patientdata'], "text"),
                       GetSQLValueString($_POST['grosspathology'], "text"),
                       GetSQLValueString($_POST['histology'], "text"),
                       GetSQLValueString($_POST['comment'], "text"),
                       GetSQLValueString($ppu->files("presentation")->fileName, "text"),
                       GetSQLValueString($_POST['web_url'], "text"),
                       GetSQLValueString($_POST['anat_diag'], "text"),
                       GetSQLValueString($_POST['references'], "text"),
                       GetSQLValueString($_POST['case_id'], "int"));

  mysql_select_db($database_connDigiPath, $connDigiPath);
  $Result1 = mysql_query($updateSQL, $connDigiPath) or die(mysql_error());
}
?>
.
.
.
<input name="presentation" type="file" id="presentation" onchange="<?php echo $ppu->getValidateCode() ?>;return document.MM_returnValue" value="<?php echo $row_rsCases['presentation']; ?>" size="32" />

Replies

Replied 20 Mar 2014 10:22:40
20 Mar 2014 10:22:40 Teodor Kuduschiev replied:
Hello,
Please change:
presentation=%s to presentation=IFNULL(%s,presentation) this will be improved in the next update.
Replied 20 Mar 2014 13:46:45
20 Mar 2014 13:46:45 David Woolley replied:
Thanks so much Teodor!
That did the trick. Hope the next PPU3 update does this automatically.
By the way I can't get the Progress Bars working - using PHP 5.4.7
Cheers
Dave
Replied 20 Mar 2014 15:00:59
20 Mar 2014 15:00:59 tim martyn replied:
Great, works like a dream. Thanks a lot Teodor, much appreciated.

(and thanks Dave for reposting)
Replied 26 Mar 2014 16:27:02
26 Mar 2014 16:27:02 Teodor Kuduschiev replied:
Hello
This problem is fixed in the latest version. Please update.
Replied 18 Jun 2015 17:45:41
18 Jun 2015 17:45:41 Adrian Leontovich replied:
This is NOT fixed in the latest version. I just installed it and it's still an issue. One difference is that I'm using mySQLi, so I don't know if that's a part of the problem or not. Here's my mySQLi/PHP update code:


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();
}
Replied 05 Jun 2016 10:55:02
05 Jun 2016 10:55:02 Nick Green replied:
I have the exact same problem and have only just installed Pure Upload 3 today.

Background
Can't get on with the DMXzone Connector functions so using MySQLi from Webassist but that shouldn't be an issue.
  • Insert function working great.
  • Update function (when changing image) working great.
  • If I don't change the image and submit the form the image is overwritten in the database.


I have binded my Recordset value to the file field and when the page is loaded I can see it in source code. However when submitting the form it's just overwritten without keeping the value of the image field.

My update function is pretty much the same as Adrian's...any suggestions?

Cheers
Nick


UPDATE @ 12:00 on 5th June 2016.

I've managed a work around based on a post above. In essence I have replaced the WA_DEFAULT value at the end of the bindColumn to be the recordset value. Therefore if the value that Pure Upload is seeing is blank, then I just replace the default value with what the RS had anyway. Make sure that you have your recordset before the Pure Upload function otherwise it won't see the original data.


My fix
$UpdateQuery->bindColumn("image", "s", "".((isset($_POST["image"]))?$_POST["image"]:"")  ."", $rsProductDetail->getColumnval("image"));


This will definitely help you Adrian, but not sure about others. This really should be fixed as a really common function to use.

Reply to this topic