Pure PHP Upload 2 Support Product Page

Leave existing file name in Database?

Shared 10 Sep 2007 19:34:09
1
likes this idea
10 Sep 2007 19:34:09 John Langer posted:
Using v 2.1.4 with PHP

I've implemented this together with other inserts (Name, address, image etc). All works well. I have insert, display, and update pages. The problem is with the update.

I can show the update record page with the existing record details including the image. On this page I have the upload file field with Pure PHP Upload behaviours applied to it. The trouble comes when I don't want to upload a new image, just perhaps want to do a change of address or phone number but I'm happy with the existing image. If I leave the file upload field blank it deletes it from the database and there fore no longer shows it when called dynamically.

As an example I have in the initial value field for the email address < ?php echo(str_replace('"', '"', $row_cms_staff['email'])); ? > and in the image file field < ?php echo(str_replace('"', '"', $row_cms_staff['image'])); ? > so I fail to see why the image field in the database is being erased but the email address isn't. Any ideas what I'm doing wrong or how to get around this?

John

Replies

Replied 10 Sep 2007 20:12:02
10 Sep 2007 20:12:02 John Langer replied:
I seem to have posted this in the wrong section of the forum. My apologies.

John
Replied 11 Sep 2007 11:33:40
11 Sep 2007 11:33:40 Georgi Kralev replied:
Hi John,

QuoteThe trouble comes when I don't want to upload a new image, just perhaps want to do a change of address or phone number but I'm happy with the existing image. If I leave the file upload field blank it deletes it from the database and there fore no longer shows it when called dynamically.


For update statement Pure PHP Upload uses the following syntax:


$updateSQL = sprintf("UPDATE images SET image=IFNULL(%s,image) WHERE id=%s",
                       GetSQLValueString($_POST['fileField'], "text"),
                       GetSQLValueString($_POST['id'], "int"));



Where IFNULL function of mySQL preform check if the uploaded value is Null and in this case use the old value.
If you use the same approach you should not experience this issue.
You will update the other values of the record (email etc) and retain the old image (by leaving file upload field blank)

I hope this help you.

Regards,

Georgi Kralev

----------------------------------
Support - www.DMXzone.com
Replied 11 Sep 2007 12:05:52
11 Sep 2007 12:05:52 John Langer replied:
Hi George,

Thanks for the reply.

I'm afraid however that I don't understand any of that. Sorry. I'm happy to use server behaviours and extensions etc. but when it comes to messing with the code I'm way out of my depth. Is it possible to explain it again but this time assume that I know nothing.

Sorry to be a nuisance.

John
Replied 12 Sep 2007 09:37:18
12 Sep 2007 09:37:18 Georgi Kralev replied:
Hi John,

If you use only the Server Behaviors of Dreamweaver and Pure PHP Upload extension the code that I mentioned should be generated automatically. Perhaps, there is some problem with the code of your php file.
If you provide your page I could try to find out what is causing the issue.

Regards,

Georgi Kralev

----------------------------------
Support - www.DMXzone.com
Replied 12 Sep 2007 09:44:17
12 Sep 2007 09:44:17 John Langer replied:
Hi George, it's ok, I've managed to work it out.

Many thanks for your interest

John
Replied 29 Sep 2010 10:03:06
29 Sep 2010 10:03:06 David Casey replied:
I'm having the same problem when I update a field it deletes the image record, I tried your example with no luck.

I get the following error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'PageImage=IFNULL (NULL) WHERE PageID='Test Page45tt'' at line 1

My code is

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form3")) {
  $updateSQL = sprintf("UPDATE MainPages SET PageImage=IFNULL (%s, PageImage PageName=%s, PageHeading=%s, PageDetail=%s WHERE PageID=%s",
                       GetSQLValueString($_POST['PageImage'], "text"),
                       GetSQLValueString($_POST['PageName'], "text"),
                       GetSQLValueString($_POST['PageHeading'], "text"),
                       GetSQLValueString($_POST['PageContent'], "text"),
                       GetSQLValueString($_POST['PageID'], "int"));

  mysql_select_db($database_localhost, $localhost);

Replied 29 Sep 2010 10:37:37
29 Sep 2010 10:37:37 David Casey replied:
Also tried:

  $updateSQL = sprintf("UPDATE MainPages SET <b>PageImage=IFNULL (%s, PageName=%s, PageHeading=%s, PageDetail=%s)</b> WHERE PageID=%s",
                       GetSQLValueString($_POST['PageImage'], "text"),
                       GetSQLValueString($_POST['PageName'], "text"),
                       GetSQLValueString($_POST['PageHeading'], "text"),
                       GetSQLValueString($_POST['PageContent'], "text"),
                       GetSQLValueString($_POST['PageID'], "int"));


and just get message

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'PageImage=IFNULL (NULL, PageName='Test Page45tt', PageHeading='Test page 145t' at line 1

Can someone please help? I noticed not too many people active in this forum does this mean there is a better solution out there than pp2?
Replied 01 Oct 2010 13:18:33
01 Oct 2010 13:18:33 Miroslav Zografski replied:
Hello David,

Please, check once again the topic you have your fix from.
There are some unwanted characters sneaked into the code you should use. Please, consider removing them from your second test code.

Regards,
Replied 17 Jun 2015 17:02:41
17 Jun 2015 17:02:41 Adrian Leontovich replied:
I'm having this problem, but with mySQLi, the fileField value is being cleared on Update:


if (isset($_POST["button"]) || isset($_POST["button_x"])) {
  $UpdateQuery = new WA_MySQLi_Query($Conn);
  $UpdateQuery->Action = "update";
  $UpdateQuery->Table = "TableName";
  $UpdateQuery->bindColumn("DocID", "s", "".((isset($_POST["DocID"]))?$_POST["DocID"]:"")  ."", "WA_DEFAULT");
  $UpdateQuery->bindColumn("FileName", "s", "".((isset($_FILES["fileField"]))?$_FILES["fileField"]["name"]:"")  ."", "WA_DEFAULT");
  $UpdateQuery->addFilter("DocID", "=", "i", "".($_GET['DocID'])  ."");
  $UpdateQuery->execute();
  $UpdateGoTo = "test.php";
  if (function_exists("rel2abs")) $UpdateGoTo = $UpdateGoTo?rel2abs($UpdateGoTo,dirname(__FILE__)):"";
  $UpdateQuery->redirect($UpdateGoTo);
}
Replied 04 Sep 2015 19:23:39
04 Sep 2015 19:23:39 Adrian Leontovich replied:
Any answer on this with mysqli???

Reply to this topic