PDA

View Full Version : insert images to database


warrenphillips25336771
03-16-2009, 08:57 AM
Hi

I have the supersuite and have built a shopping cart using ecart and the backend using wada, only thing i don't use is the dfp, as i needed one that would resize, can someone please help with the coding to insert the image that relates to the product in the database, i have checked and it does uploads to the server images folder but does not insert in the database, surely it is just missing a hidden php field, can anyone help please.

thanks

Ray Borduin
03-16-2009, 09:24 AM
What are you using to uplaod? It wouldn't be a hidden field... probably a function call or snippit... it depends on how you are doing the upload.

warrenphillips25336771
03-16-2009, 11:03 AM
Hi Ray

I am using dmx pure upload with the smart image processor, the only reason for this is due to the automatic resizing feature and i could not wait for dfp to come out, this is the code used by the uploader

<?php require_once("../Connections/beads2.php"); ?>
<?php require_once("../WA_ValidationToolkit/WAVT_Scripts_PHP.php"); ?>
<?php require_once("../WA_ValidationToolkit/WAVT_ValidatedForm_PHP.php"); ?>
<?php require_once( "../WA_Globals/WA_Globals.php" ); ?>
<?php require_once("../WA_DataAssist/WA_AppBuilder_PHP.php"); ?>
<?php require_once( "../WA_SecurityAssist/Helper_PHP.php" ); ?>
<?php
if (!WA_Auth_RulePasses("Administrator")){
WA_Auth_RestrictAccess("users_LogIn.php");
}
?>
<?php require_once('../ScriptLibrary/incPureUpload.php'); ?>
<?php require_once('../ScriptLibrary/incResize.php'); ?>
<?php
// Pure PHP Upload 2.1.7
$ppu = new pureFileUpload();
$ppu->path = "../images/thumbs";
$ppu->extensions = "GIF,JPG,JPEG,BMP,PNG";
$ppu->formName = "WADAInsertForm";
$ppu->storeType = "file";
$ppu->sizeLimit = "";
$ppu->nameConflict = "uniq";
$ppu->requireUpload = "true";
$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.7");
$ppu->doUpload();

// Smart Image Processor 1.0.7
if (isset($HTTP_GET_VARS['GP_upload'])) {
$sip = new resizeUploadedFiles($ppu);
$sip->component = "GD2";
$sip->resizeImages = "true";
$sip->aspectImages = "true";
$sip->maxWidth = "200";
$sip->maxHeight = "200";
$sip->quality = "80";
$sip->makeThumb = "false";
$sip->pathThumb = "";
$sip->aspectThumb = "true";
$sip->naming = "suffix";
$sip->suffix = "_small";
$sip->maxWidthThumb = "";
$sip->maxHeightThumb = "";
$sip->qualityThumb = "70";
$sip->checkVersion("1.0.7");
$sip->doResize();

$resizeGoTo = "items_results.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$resizeGoTo .= (strpos($resizeGoTo, '?')) ? "&" : "?";
$resizeGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $resizeGoTo));
}

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";
}
}

// WA Application Builder Insert
if (isset($_POST["Insert_x"])) // Trigger
{
$WA_connection = $beads2;
$WA_table = "items";
$WA_sessionName = "WADA_Insert_items";
$WA_redirectURL = "items_Detail.php";
$WA_keepQueryString = false;
$WA_indexField = "ItemID";
$WA_fieldNamesStr = "ItemCatID|ItemName|ItemShortDesc|ItemLongDesc|Item Price|ItemThumb|ItemImage|ItemAv";
$WA_fieldValuesStr = "".((isset($_POST["ItemCatID"]))?$_POST["ItemCatID"]:"") ."" . "|" . "".((isset($_POST["ItemName"]))?$_POST["ItemName"]:"") ."" . "|" . "".((isset($_POST["ItemShortDesc"]))?$_POST["ItemShortDesc"]:"") ."" . "|" . "".((isset($_POST["ItemLongDesc"]))?$_POST["ItemLongDesc"]:"") ."" . "|" . "".((isset($_POST["ItemPrice"]))?$_POST["ItemPrice"]:"") ."" . "|" . "".((isset($_POST["ItemThumb"]))?$_POST["ItemThumb"]:"") ."" . "|" . "".((isset($_POST["ItemImage"]))?$_POST["ItemImage"]:"") ."" . "|" . "".((isset($_POST["ItemAv"]))?$_POST["ItemAv"]:"") ."";
$WA_columnTypesStr = "none,none,NULL|',none,''|',none,''|',none,''|none, none,NULL|',none,''|',none,''|none,none,NULL";
$WA_fieldNames = explode("|", $WA_fieldNamesStr);
$WA_fieldValues = explode("|", $WA_fieldValuesStr);
$WA_columns = explode("|", $WA_columnTypesStr);
$WA_connectionDB = $database_beads2;
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);
}
}
?>
<link href="../WA_DataAssist/styles/Ultramodern_Poppy.css" rel="stylesheet" type="text/css" />
<link href="../WA_DataAssist/styles/Arial.css" rel="stylesheet" type="text/css" />
<script language='JavaScript' src='../ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
<!-- InstanceEndEditable -->
</head>

<body>

<div id="outerWrapper">
<div id="contentWrapper">
<div id="rightColumn1"><!-- InstanceBeginEditable name="Menu" --> <ul class="level-0" id="cssmw">
<li><a href="index.php">home</a></li>
<li><a href="content_Results.php">content</a></li>
<li><a href="itemcategory_Results.php">category</a></li>
<li><a href="items_Results.php">products</a></li>
<li><a href="orderdetails_Results.php">orderdetails</a></li>
<li><a href="orders_Results.php">orders</a></li>
<li><a href="users_Results.php">users</a></li>
<li><a href="weekly.php">weekly</a></li>
</ul>
<script type="text/javascript">if(window.attachEvent) { window.attachEvent("onload", function() { cssmw.intializeMenu('cssmw'); }); } else if(window.addEventListener) { window.addEventListener("load", function() { cssmw.intializeMenu('cssmw'); }, true); }</script><!-- InstanceEndEditable --></div>
<div id="content"><!-- InstanceBeginEditable name="content" -->

<div class="WADAInsertContainer">
<form action="<?php echo $GP_uploadAction; ?>" method="post" enctype="multipart/form-data" name="WADAInsertForm" id="WADAInsertForm" onsubmit="checkFileUpload(this,'GIF,JPG,JPEG,BMP,PNG',true,' ','','','','','','');return document.MM_returnValue">
<div class="WADAHeader">Insert Record</div>
<table class="WADADataTable" cellpadding="0" cellspacing="0" border="0">
<tr>
<th class="WADADataTableHeader">Item Cat ID:</th>
<td class="WADADataTableCell"><?php
mysql_select_db($database_Connbsm);
$r=mysql_query("SELECT * FROM itemcategory;");
?>
<select name="ItemCatID" id="ItemCatID">
<?php
while ($rs=mysql_fetch_array($r)){
?>
<option value="<?php echo $rs['ItemCatID']; ?>"><?php echo $rs['ItemCatName']; ?></option>
<?php } ?>
</select></td>
</tr>
<tr>
<th class="WADADataTableHeader">Item Name:</th>
<td class="WADADataTableCell"><input type="text" name="ItemName" id="ItemName" value="" size="32" /></td>
</tr>
<tr>
<th class="WADADataTableHeader">Item Short Desc:</th>
<td class="WADADataTableCell"><input type="text" name="ItemShortDesc" id="ItemShortDesc" value="" size="32" /></td>
</tr>
<tr>
<th class="WADADataTableHeader">ItemLongDesc:</th>
<td class="WADADataTableCell"><input type="text" name="ItemLongDesc" id="ItemLongDesc" value="" size="32" /></td>
</tr>
<tr>
<th class="WADADataTableHeader">Item Price:</th>
<td class="WADADataTableCell"><input type="text" name="ItemPrice" id="ItemPrice" value="" size="32" /></td>
</tr>
<tr>
<th class="WADADataTableHeader">ItemThumb:</th>
<td class="WADADataTableCell"><label>
<input name="thumb" type="file" id="thumb" onchange="checkOneFileUpload(this,'GIF,JPG,JPEG,BMP,PNG',tru e,'','','','','','','')" />
</label></td>
</tr>
<tr>
<th class="WADADataTableHeader">ItemImage:</th>
<td class="WADADataTableCell"><input type="text" name="ItemImage" id="ItemImage" value="" size="32" /></td>
</tr>
<tr>
<th class="WADADataTableHeader">ItemAv:</th>
<td class="WADADataTableCell"><input type="text" name="ItemAv" id="ItemAv" value="" size="32" /></td>
</tr>
</table>
<div class="WADAButtonRow">
<table class="WADADataNavButtons" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="WADADataNavButtonCell" nowrap="nowrap"><input type="image" name="Insert" id="Insert" value="Insert" alt="Insert" src="../WA_DataAssist/images/Poppy/Ultramodern_insert.gif" /></td>
<td class="WADADataNavButtonCell" nowrap="nowrap"><a href="items_Results.php" title="Cancel"><img border="0" name="Cancel" id="Cancel" alt="Cancel" src="../WA_DataAssist/images/Poppy/Ultramodern_cancel.gif" /></a></td>
</tr>
</table>
<input name="WADAInsertRecordID" type="hidden" id="WADAInsertRecordID" value="" />

Ray Borduin
03-16-2009, 11:10 AM
OK, so it will probably be an attribute of the $ppu object.... so in dataAssist you will enter something like: <?php echo($ppu->uploadedFileName); ?>

Now, I'm not sure if it is "uploadedFileName" or what the value is, since that information is probably in their documentation, or maybe they have Bindings available for it (that is how we would do it), or you could look for what you use referenced in: <?php require_once('../ScriptLibrary/incPureUpload.php'); ?>

warrenphillips25336771
03-16-2009, 11:17 AM
thanks ray

warrenphillips25336771
03-17-2009, 03:05 PM
Ray

so i am using datassist (this image uploader is in the admin side) i added a file field, added my dmx zone uploader and then i ADDED an insert record behaviour as this is what was missing, but it duplictaes the item added 4 times (2 times for the insert and 2 times for the update) am i doing something wrong? surely datassist should sort of handle this for me. can you give me a clue please?

warrenphillips25336771
03-17-2009, 03:35 PM
OK, so it will probably be an attribute of the $ppu object.... so in dataAssist you will enter something like: <?php echo($ppu->uploadedFileName); ?>

Now, I'm not sure if it is "uploadedFileName" or what the value is, since that information is probably in their documentation, or maybe they have Bindings available for it (that is how we would do it), or you could look for what you use referenced in: <?php require_once('../ScriptLibrary/incPureUpload.php'); ?>

so how do you add this to the data assist? sorry ray i am thick but learning :)

Ray Borduin
03-18-2009, 07:58 AM
you will enter something like: <?php echo($ppu->uploadedFileName); ?>

as the value for the field in the DataAssist Insert Record server behavior on the page.

Ray Borduin
03-18-2009, 07:58 AM
You must have done something wrong, but it isn't obvious what it is without looking at your page or having more information.