close ad
WARNING: Do Not Install the DREAMWEAVER CC 2017 or 2018 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

multi image upload

Thread began 6/01/2010 5:33 am by georgina_barrett_187762 | Last modified 6/10/2010 10:02 am by Jason Byrnes | 1621 views | 11 replies |

georgina_barrett_187762

multi image upload

I am having problems with a multi image upload. I have successfully done it before and can't see the problem. I followed the tutorial - but still no joy. I have created a simple page with a drop down list to get the resortID and a repeated region image file upload - however when I click submit neither the image gets uploaded nor the file name gets added to the database. To test the problem I changed the file field to a text field and that did submit the text into the database fine however when I changed it back to a file field it stopped working again.
This is the top part of my code:
<?php require_once('../Connections/exclusive.php'); ?>
<?php require_once("../WA_DataAssist/WA_AppBuilder_PHP.php"); ?>
<?php require_once("../WA_DigitalFilePro/HelperPHP.php"); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$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;
}
}

mysql_select_db($database_exclusive, $exclusive);
$query_resort = "SELECT resortdetails.ID, resortdetails.Resort, resortdetails.Country FROM resortdetails ORDER BY resortdetails.Resort, resortdetails.Country";
$resort = mysql_query($query_resort, $exclusive) or die(mysql_error());
$row_resort = mysql_fetch_assoc($resort);
$totalRows_resort = mysql_num_rows($resort);?>
<?php
// WA_UploadResult1 Params Start
$WA_UploadResult1_Params = array();
// WA_UploadResult1_1 Start
$WA_UploadResult1_Params["WA_UploadResult1_1"] = array(
'UploadFolder' => "../photo/",
'FileName' => "[FileName]",
'DefaultFileName' => "",
'ResizeType' => "2",
'ResizeWidth' => "300",
'ResizeHeight' => "120",
'ResizeFillColor' => "#FFFFFF" );
// WA_UploadResult1_1 End
// WA_UploadResult1 Params End
?>
<?php
WA_DFP_SetupUploadStatusStruct("WA_UploadResult1");
if($_SERVER["REQUEST_METHOD"] == "POST"){
WA_DFP_UploadFiles("WA_UploadResult1", "image_".$RepeatSelectionCounter_1 ."", "2", "[NewFileName]_[Increment]", "true", $WA_UploadResult1_Params);
}
?>
<?php
// WA DataAssist Multiple Inserts
if ($_SERVER["REQUEST_METHOD"] == "POST") // Trigger
{
if (!session_id()) session_start();
$WA_loopedFields = array("");
$WA_connection = $exclusive;
$WA_table = "resortimages";
$WA_redirectURL = "resortdetails_Detail.php";
$WA_keepQueryString = true;
$WA_fieldNamesStr = "resortID|image";
$WA_columnTypesStr = "none,none,NULL|',none,''";
$WA_insertIfNotBlank = "image";
$WA_fieldNames = explode("|", $WA_fieldNamesStr);
$WA_columns = explode("|", $WA_columnTypesStr);
$WA_connectionDB = $database_exclusive;
$WA_multipleInsertCounter = 0;
mysql_select_db($WA_connectionDB, $WA_connection);
while (WA_AB_checkMultiInsertLoopedFieldsExist($WA_loopedFields, $WA_multipleInsertCounter)) {
if ($WA_insertIfNotBlank == "" || WA_AB_checkLoopedFieldsNotBlank(array($WA_insertIfNotBlank), $WA_multipleInsertCounter)) {
$WA_fieldValuesStr = "".((isset($_POST["resortID"]))?$_POST["resortID"]:"") ."" . "|" . "".$WA_DFP_UploadStatus["WA_UploadResult1"]["serverFileName"] ."";
$WA_fieldValues = explode("|", $WA_fieldValuesStr);
$insertParamsObj = WA_AB_generateInsertParams($WA_fieldNames, $WA_columns, $WA_fieldValues, -1);
$WA_Sql = "INSERT INTO `" . $WA_table . "` (" . $insertParamsObj->WA_tableValues . ") VALUES (" . $insertParamsObj->WA_dbValues . ")";
$MM_editCmd = mysql_query($WA_Sql, $WA_connection) or die(mysql_error());
}
$WA_multipleInsertCounter++;
}
if ($WA_redirectURL != "") {
if ($WA_keepQueryString && $WA_redirectURL != "" && isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] !== "" && sizeof($_POST) > 0) {
$WA_redirectURL .= ((strpos($WA_redirectURL, '?') === false)?"?":"&").$_SERVER["QUERY_STRING"];
}
header("Location: ".$WA_redirectURL);
}
}
?>
<?php
// RepeatSelectionCounter_1 Initialization
$RepeatSelectionCounter_1 = 0;
$RepeatSelectionCounterBasedLooping_1 = true;
$RepeatSelectionCounter_1_Iterations = "8";
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

And the form:
<form action="resortdetails_Insert_Image.php" method="post" enctype="multipart/form-data" name="WADAInsertForm" id="WADAInsertForm">

<table width="100%" border="0" cellspacing="0" cellpadding="0" class="WADADataTable">
<tr>
<th class="WADADataTableHeader">Select Resort:</th>
<td class="WADADataTableCell"><label>
<select name="resortID" id="resortID">
<?php
do {
?>
<option value="<?php echo $row_resort['ID']?>"><?php echo $row_resort['Resort']?> - <?php echo $row_resort['Country']?></option>
<?php
} while ($row_resort = mysql_fetch_assoc($resort));
$rows = mysql_num_rows($resort);
if($rows > 0) {
mysql_data_seek($resort, 0);
$row_resort = mysql_fetch_assoc($resort);
}
?>
</select>
</label></td>
</tr>
<?php
// RepeatSelectionCounter_1 Begin Loop
$RepeatSelectionCounter_1_IterationsRemaining = $RepeatSelectionCounter_1_Iterations;
while($RepeatSelectionCounter_1_IterationsRemaining--){
if($RepeatSelectionCounterBasedLooping_1 || $row_None){
?><tr>
<th class="WADADataTableHeader">Image:</th>
<td class="WADADataTableCell"><label>
<input type="hidden" name="image_mihidden_<?php echo $RepeatSelectionCounter_1; ?>" id="image_mihidden_<?php echo $RepeatSelectionCounter_1; ?>" value="1" />
<input type="file" name="image_<?php echo $RepeatSelectionCounter_1; ?>" id="image_<?php echo $RepeatSelectionCounter_1; ?>" />
</label></td>
</tr><?php
} // RepeatSelectionCounter_1 Begin Alternate Content
else{
?>
<?php } // RepeatSelectionCounter_1 End Alternate Content
if(!$RepeatSelectionCounterBasedLooping_1 && $RepeatSelectionCounter_1_IterationsRemaining != 0){
if(!$row_None && $RepeatSelectionCounter_1_Iterations == -1){$RepeatSelectionCounter_1_IterationsRemaining = 0;}
$row_None = mysql_fetch_assoc($None);
}
$RepeatSelectionCounter_1++;
} // RepeatSelectionCounter_1 End Loop
?>
<tr>
<td class="WADADataTableHeader">&nbsp;</td>
<td class="WADADataTableCell"><table class="WADADataNavButtons" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="WADADataNavButtonCell"><input type="image" name="Insert" id="Insert" value="Insert" alt="Insert" src="../WA_DataAssist/images/Pacifica/Refined_insert.gif" /></td>
<td class="WADADataNavButtonCell"><a href="resortdetails_Results.php" title="Cancel"><img border="0" id="Cancel" alt="Cancel" src="../WA_DataAssist/images/Pacifica/Refined_cancel.gif" /></a></td>
</tr>
</table> <label></label></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>

</form>

Sign in to reply to this post

Jason ByrnesWebAssist

Multi image upload cannot be done in this way.

An image upload behavior must be created for each file field on the page.

Image upload is not supported with the multi insert behavior. It would require a fair bit of hand coding to accomplish.

Sign in to reply to this post

georgina_barrett_187762

Ok - I have created 8 file fields with 8 separate image uploads and 8 seperate inserts. These all upload the image and upload the file name to the database. The problem I have is that if a file field is empty a blank record gets inserted into the database. I have tried adding isset($_POST['image1']) at the beginning of each of the insert codes ie.

// WA Application Builder Insert
if (isset($_POST["Insert_x"]) && isset($_POST['image1'])) // Trigger
{
$WA_connection = $exclusive;
$WA_table = "resortimages";
$WA_sessionName = "resortimages_resortimagesID";
$WA_redirectURL = "";
$WA_keepQueryString = false;
$WA_indexField = "resortimagesID";
$WA_fieldNamesStr = "resortID|image";
$WA_fieldValuesStr = "".$_SESSION['WADA_Insert_resortdetails'] ."" . "|" . "".$WA_DFP_UploadStatus["WA_UploadResult1"]["serverFileName"] ."";
$WA_columnTypesStr = "none,none,NULL|',none,''";
$WA_fieldNames = explode("|", $WA_fieldNamesStr);
$WA_fieldValues = explode("|", $WA_fieldValuesStr);
$WA_columns = explode("|", $WA_columnTypesStr);
$WA_connectionDB = $database_exclusive;
mysql_select_db($WA_connectionDB, $WA_connection);
if (!session_id()) session_start();
$insertParamsObj = WA_AB_generateInsertParams($WA_fieldNames, $WA_columns, $WA_fieldValues, -1);
$WA_Sql = "INSERT INTO `" . $WA_table . "` (" . $insertParamsObj->WA_tableValues . ") VALUES (" . $insertParamsObj->WA_dbValues . ")";
$MM_editCmd = mysql_query($WA_Sql, $WA_connection) or die(mysql_error());
$_SESSION[$WA_sessionName] = mysql_insert_id();
if ($WA_redirectURL != "") {
if ($WA_keepQueryString && $WA_redirectURL != "" && isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] !== "" && sizeof($_POST) > 0) {
$WA_redirectURL .= ((strpos($WA_redirectURL, '?') === false)?"?":"&").$_SERVER["QUERY_STRING"];
}
header("Location: ".$WA_redirectURL);
}
}
?>

But then nothing gets inserted into the database.

Sign in to reply to this post

Jason ByrnesWebAssist

the correct syntax for checking if a file field has a value is:

php:
isset($_FILES['image1']) && $_FILES['image1'] != ""




change the trigger:

php:
if (isset($_POST["Insert_x"]) && isset($_POST['image1'])) // Trigger



to:

php:
if (isset($_POST["Insert_x"]) && (isset($_FILES['image1']) && $_FILES['image1'] != "") // Trigger
Sign in to reply to this post

georgina_barrett_187762

I added:
if (isset($_POST["Insert_x"]) && isset($_FILES['image1']) && $_FILES['image1'] != "") // Trigger
if (isset($_POST["Insert_x"]) && isset($_FILES['image2']) && $_FILES['image2'] != "") // Trigger
if (isset($_POST["Insert_x"]) && isset($_FILES['image3']) && $_FILES['image3'] != "") // Trigger
...etc to each of the inserts- i.e.
<?php
// WA Application Builder Insert
if (isset($_POST["Insert_x"]) && isset($_FILES['image1']) && $_FILES['image1'] != "") // Trigger
{
$WA_connection = $exclusive;
$WA_table = "resortimages";
$WA_sessionName = "resortimages_resortimagesID";
$WA_redirectURL = "";
$WA_keepQueryString = false;
$WA_indexField = "resortimagesID";
$WA_fieldNamesStr = "resortID|image";
$WA_fieldValuesStr = "".$_SESSION['WADA_Insert_resortdetails'] ."" . "|" . "".$WA_DFP_UploadStatus["WA_UploadResult1"]["serverFileName"] ."";
$WA_columnTypesStr = "none,none,NULL|',none,''";
$WA_fieldNames = explode("|", $WA_fieldNamesStr);
$WA_fieldValues = explode("|", $WA_fieldValuesStr);
$WA_columns = explode("|", $WA_columnTypesStr);
$WA_connectionDB = $database_exclusive;
mysql_select_db($WA_connectionDB, $WA_connection);
if (!session_id()) session_start();
$insertParamsObj = WA_AB_generateInsertParams($WA_fieldNames, $WA_columns, $WA_fieldValues, -1);
$WA_Sql = "INSERT INTO `" . $WA_table . "` (" . $insertParamsObj->WA_tableValues . ") VALUES (" . $insertParamsObj->WA_dbValues . ")";
$MM_editCmd = mysql_query($WA_Sql, $WA_connection) or die(mysql_error());
$_SESSION[$WA_sessionName] = mysql_insert_id();
if ($WA_redirectURL != "") {
if ($WA_keepQueryString && $WA_redirectURL != "" && isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] !== "" && sizeof($_POST) > 0) {
$WA_redirectURL .= ((strpos($WA_redirectURL, '?') === false)?"?":"&").$_SERVER["QUERY_STRING"];
}
header("Location: ".$WA_redirectURL);
}
}
?>



however they still insert blank entries into the database.

Sign in to reply to this post

Jason ByrnesWebAssist

please post a copy of the php page compressed into a zip archive so I can examine the entire code in context.

Sign in to reply to this post

georgina_barrett_187762

Thank you. I have attached it.

Attached Files
resortdetails_Insert.zip
Sign in to reply to this post

Jason ByrnesWebAssist

the code is correct, that will prevent blank entries from being added to the database.

In the body of the page, add todays date and upload it again to make sure the changes are being uploaded to the server correctly. When you load the page in the browser you should the data on the page to indicate that the code changes are making it up to the server before testing.

Sign in to reply to this post

georgina_barrett_187762

I have added the date and reuploaded - and it has uploaded the page however it is still inserting empty records into the resortimages table.

I tried removing value="" from each of the file fields (because I added those) <input type="file" name="image8" id="image8" value="" />

But it still uploads empty records.

Sign in to reply to this post

Jason ByrnesWebAssist

OK, I see the problem now, the trigger should be:

php:
if (isset($_POST["Insert_x"]) && isset($_FILES['image1']) && $_FILES['image1']['name'] != "") // Trigger
Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...