Pure PHP Upload 2 Support Product Page

Blank values sent when file not changed

Asked 09 Sep 2010 09:12:03
1
has this question
09 Sep 2010 09:12:03 Andy Harper posted:
Greetings, I have a simple for that manages images for a rotator. Each record has a date, title, live, and url field. PHP Upload 2 works great if I'm updating the image. However, if the image isn't changing but one of the other fields is, when the update is sent my url field gets a blank entry. I am setting the value=<? ...?> on the file field, and when I view source on the form in the browser it shows the proper data being pulled into the page. When I submit however, it sends a blank.

I followed the instructions in the manual, but unless I set an image with the file field every time I use the form, it sends a blank. I used to do this with an older version but now I can't get it to work at all!

www.festivaloffaiths.org/cms/formdummy.php

Please advise!
Edited by - Andy Harper on 09 Sep 2010  09:12:23

Replies

Replied 09 Sep 2010 10:15:35
09 Sep 2010 10:15:35 Miroslav Zografski replied:
Hello Andy,

Are you populating the form from a recordset? Could you post your page source here or pass it on my e-mail:

Regards,
Replied 09 Sep 2010 18:19:23
09 Sep 2010 18:19:23 Andy Harper replied:
Emailed it to you, thanks!
Replied 09 Sep 2010 18:53:18
09 Sep 2010 18:53:18 Andy Harper replied:
...and here's the code for others to view.

<?php require_once('../Connections/data1.php'); ?>
<?php require_once('../ScriptLibrary/incPureUpload.php'); ?>
<?php
// Pure PHP Upload 2.1.10
$ppu = new pureFileUpload();
$ppu->path = "../img";
$ppu->extensions = "GIF,JPG,JPEG,BMP,PNG";
$ppu->formName = "form1";
$ppu->storeType = "file";
$ppu->sizeLimit = "";
$ppu->nameConflict = "over";
$ppu->requireUpload = "false";
$ppu->minWidth = "";
$ppu->minHeight = "";
$ppu->maxWidth = "";
$ppu->maxHeight = "";
$ppu->saveWidth = "";
$ppu->saveHeight = "";
$ppu->timeout = "600";
$ppu->progressBar = "";
$ppu->progressWidth = "";
$ppu->progressHeight = "";
$ppu->redirectURL = "";
$ppu->checkVersion("2.1.10");
$ppu->doUpload();

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if (isset($editFormAction)) {
  if (isset($_SERVER['QUERY_STRING'])) {
	  if (!eregi("GP_upload=true", $_SERVER['QUERY_STRING'])) {
  	  $editFormAction .= "&GP_upload=true";
		}
  } else {
    $editFormAction .= "?GP_upload=true";
  }
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE featureimage SET `date`=%s, live=%s, title=%s, url=%s WHERE PRKey=%s",
                       GetSQLValueString($_POST['date'], "date"),
                       GetSQLValueString($_POST['live'], "text"),
                       GetSQLValueString($_POST['title'], "text"),
                       GetSQLValueString($_POST['url'], "text"),
                       GetSQLValueString($_POST['PRKey'], "int"));

  mysql_select_db($database_data1, $data1);
  $Result1 = mysql_query($updateSQL, $data1) or die(mysql_error());

  $updateGoTo = "../thanks.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

mysql_select_db($database_data1, $data1);
$query_rotator = "SELECT * FROM featureimage WHERE misc1 = '1'";
$rotator = mysql_query($query_rotator, $data1) or die(mysql_error());
$row_rotator = mysql_fetch_assoc($rotator);
$totalRows_rotator = mysql_num_rows($rotator);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<script language='JavaScript' src='../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>

</head>

<body>
<form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="form1" id="form1" onsubmit="checkFileUpload(this,'GIF,JPG,JPEG,BMP,PNG',false,'','','','','','','');return document.MM_returnValue">
  <table width="700" border="0" cellpadding="5">
    <tr>
      <td width="101" align="left" valign="top">Date</td>
      <td width="589"><input name="date" type="text" id="date" value="<?php echo $row_rotator['date']; ?>" size="45" /></td>
    </tr>
    <tr>
      <td align="left" valign="top">Live</td>
      <td><select name="live" id="live" title="<?php echo $row_rotator['live']; ?>">
        <option value="valueyes">Yes</option>
        <option value="no">No</option>
      </select></td>
    </tr>
    <tr>
      <td align="left" valign="top">Title</td>
      <td><input name="title" type="text" id="title" value="<?php echo $row_rotator['title']; ?>" /></td>
    </tr>
    <tr>
      <td align="left" valign="top"> Image URL</td>
      <td><input name="url" type="file" id="url" onchange="checkOneFileUpload(this,'GIF,JPG,JPEG,BMP,PNG',false,'','','','','','','')" value="<?php echo $row_rotator['url']; ?>" /></td>
    </tr>
    <tr>
      <td align="left" valign="top">Image</td>
      <td><img src="/img/<?php echo $row_rotator['url']; ?>" alt="" name="image" width="145" height="74" id="image" /></td>
    </tr>
    <tr>
      <td align="left" valign="top"><input name="PRKey" type="hidden" id="PRKey" value="<?php echo $row_rotator['PRKey']; ?>" /></td>
      <td><input type="submit" name="submit" id="submit" value="Submit" /></td>
    </tr>
  </table>
  <input type="hidden" name="MM_update" value="form1" />
</form>
</body>
</html>
<?php
mysql_free_result($rotator);
?>



Replied 09 Sep 2010 19:34:50
09 Sep 2010 19:34:50 Miroslav Zografski replied:
Hello Andy,

I've set up a test site I have passed you the URL in a mail. For me that stuff works as expected. What i do notice is that you rely on getting the first record from the DB table. I did my test with record filtering depending on URL Parameter.

Try setting such an example.

Regards,
Replied 09 Sep 2010 19:55:36
09 Sep 2010 19:55:36 Andy Harper replied:
OK thanks. I'll watch my inbox! (nothing yet)
Replied 10 Sep 2010 01:12:32
10 Sep 2010 01:12:32 Andy Harper replied:
Still nothing to my email...? limitedwave at gmail dot com. Thanks!
Replied 10 Sep 2010 01:33:39
10 Sep 2010 01:33:39 Andy Harper replied:
Changed to a URL variable instead of Entered Value and it works!!! Thank you for the advice. Can you possibly explain why it functions that way? Or why the two methods cause different outcomes?
Replied 10 Sep 2010 09:49:00
10 Sep 2010 09:49:00 Miroslav Zografski replied:
Hello Andy,

Sorry for the delay of my e-mail - by some reason ( perhaps found in the 40cm-from-the-monitor-device ) it ended up in my Draft folder and was not send.
Well... I'll see to this and will try to get the reason. However, I think it is something related to the DW standard Server behaviors, but I'll check.

By the way - if you like to hide the variable passed you can use session variable instead. (for better security )

Regards,

Reply to this topic