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

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

Duplicate code problem? Done nothing other than use eCart wizards.

Thread began 3/10/2014 11:16 am by Nathon Jones Web Design | Last modified 3/10/2014 1:40 pm by Nathon Jones Web Design | 202 views | 3 replies

Nathon Jones Web Design

Duplicate code problem? Done nothing other than use eCart wizards.

I've used the eCart wizards and dialogue boxes but, upon checking my code (with my limited knowledge of PHP I would add), I can't help but feel that there is a lot of duplication which I'm concerned will cause errors. Here's my shopping basket page...

<?php

error_reporting(E_ALL);

ini_set('display_errors','on');

?>
<?php require_once('Connections/njMySQL.php'); ?>
<?php
//WA eCart Include
require_once("WA_eCart/LEDCart_PHP.php");
?>
<?php
$LEDCart->GetContent();
?>
<?php
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;
}
}

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

$colname_rsPROD = "-1";
if (isset($_GET['lbid'])) {
$colname_rsPROD = $_GET['lbid'];
}
mysql_select_db($database_njMySQL, $njMySQL);
$query_rsPROD = sprintf("SELECT LEDid, LEDtitle, LEDtitlemeta, LEDdesc, LEDmetadesc, LEDproductcode, LEDtypeID, LEDtypename, LEDtypeURL, LEDbaseID, LEDbasename, LEDstyleID, LEDstylename, LEDwattage, LEDcolourID, LEDdimmable, LEDcover, LEDlumens, LEDbrightness, LEDbeamangle, LEDsensor, LEDnoofchips, LEDprice, LEDnetweight, LEDwidth, LEDheight, LEDvoltage, LEDacdc, LEDreplacementfor, LEDavglife, LEDcerohs, LEDimgtmb, LEDimg, LEDimg1, LEDimg2, LEDimg3, LEDdelete, LEDoffer FROM qryLEDallprods WHERE LEDid = %s", GetSQLValueString($colname_rsPROD, "int"));
$rsPROD = mysql_query($query_rsPROD, $njMySQL) or die(mysql_error());
$row_rsPROD = mysql_fetch_assoc($rsPROD);
$totalRows_rsPROD = mysql_num_rows($rsPROD);

$paramItem_rsCOLOUR = "-1";
if (isset($row_rsPROD['LEDid'])) {
$paramItem_rsCOLOUR = $row_rsPROD['LEDid'];
}
mysql_select_db($database_njMySQL, $njMySQL);
$query_rsCOLOUR = sprintf("SELECT LEDprodoptions.LEDprodoptionincr, LEDprodoptions.LEDprodoptionsID, LEDvars.LEDvarname, LEDvars.LEDprodvarID, LEDprodvars.LEDprodvarname FROM LEDvars INNER JOIN LEDprodoptions ON LEDvars.LEDvarID = LEDprodoptions.LEDvarID INNER JOIN LEDprodvars ON LEDvars.LEDprodvarID = LEDprodvars.LEDprodvarID WHERE LEDprodvars.LEDprodvarname = 'Colour' AND LEDprodoptions.LEDid = %s", GetSQLValueString($paramItem_rsCOLOUR, "int"));
$rsCOLOUR = mysql_query($query_rsCOLOUR, $njMySQL) or die(mysql_error());
$row_rsCOLOUR = mysql_fetch_assoc($rsCOLOUR);
$totalRows_rsCOLOUR = mysql_num_rows($rsCOLOUR);

$paramItem_rsDIMM = "-1";
if (isset($row_rsPROD['LEDid'])) {
$paramItem_rsDIMM = $row_rsPROD['LEDid'];
}
mysql_select_db($database_njMySQL, $njMySQL);
$query_rsDIMM = sprintf("SELECT LEDprodoptions.LEDprodoptionincr, LEDprodoptions.LEDprodoptionsID, LEDvars.LEDvarname, LEDvars.LEDprodvarID, LEDprodvars.LEDprodvarname FROM LEDvars INNER JOIN LEDprodoptions ON LEDvars.LEDvarID = LEDprodoptions.LEDvarID INNER JOIN LEDprodvars ON LEDvars.LEDprodvarID = LEDprodvars.LEDprodvarID WHERE LEDprodvars.LEDprodvarname = 'Dimmable' AND LEDprodoptions.LEDid = %s", GetSQLValueString($paramItem_rsDIMM, "int"));
$rsDIMM = mysql_query($query_rsDIMM, $njMySQL) or die(mysql_error());
$row_rsDIMM = mysql_fetch_assoc($rsDIMM);
$totalRows_rsDIMM = mysql_num_rows($rsDIMM);

$paramOption_rsDIMMLOOKUP = "-1";
if (isset($_POST['LEDCart_1_Dimmable_Add'])) {
$paramOption_rsDIMMLOOKUP = $_POST['LEDCart_1_Dimmable_Add'];
}
$paramItem_rsDIMMLOOKUP = "-1";
if (isset($_POST['LEDCart_1_ID_Add'])) {
$paramItem_rsDIMMLOOKUP = $_POST['LEDCart_1_ID_Add'];
}
mysql_select_db($database_njMySQL, $njMySQL);
$query_rsDIMMLOOKUP = sprintf("SELECT LEDprodoptions.LEDprodoptionincr, LEDprodoptions.LEDprodoptionsID, LEDvars.LEDvarname, LEDvars.LEDprodvarID, LEDprodvars.LEDprodvarname FROM LEDvars INNER JOIN LEDprodoptions ON LEDvars.LEDvarID = LEDprodoptions.LEDvarID INNER JOIN LEDprodvars ON LEDvars.LEDprodvarID = LEDprodvars.LEDprodvarID WHERE LEDprodvars.LEDprodvarname = 'Dimmable' AND LEDprodoptions.LEDprodoptionsID = %s AND LEDprodoptions.LEDid = %s", GetSQLValueString($paramOption_rsDIMMLOOKUP, "int"),GetSQLValueString($paramItem_rsDIMMLOOKUP, "int"));
$rsDIMMLOOKUP = mysql_query($query_rsDIMMLOOKUP, $njMySQL) or die(mysql_error());
$row_rsDIMMLOOKUP = mysql_fetch_assoc($rsDIMMLOOKUP);
$totalRows_rsDIMMLOOKUP = mysql_num_rows($rsDIMMLOOKUP);

$paramOption_rsCOLOURLOOKUP = "-1";
if (isset($_POST['LEDCart_1_Colour_Add'])) {
$paramOption_rsCOLOURLOOKUP = $_POST['LEDCart_1_Colour_Add'];
}
$paramItem_rsCOLOURLOOKUP = "-1";
if (isset($_POST['LEDCart_1_ID_Add'])) {
$paramItem_rsCOLOURLOOKUP = $_POST['LEDCart_1_ID_Add'];
}
mysql_select_db($database_njMySQL, $njMySQL);
$query_rsCOLOURLOOKUP = sprintf("SELECT LEDprodoptions.LEDprodoptionincr, LEDprodoptions.LEDprodoptionsID, LEDvars.LEDvarname, LEDvars.LEDprodvarID, LEDprodvars.LEDprodvarname FROM LEDvars INNER JOIN LEDprodoptions ON LEDvars.LEDvarID = LEDprodoptions.LEDvarID INNER JOIN LEDprodvars ON LEDvars.LEDprodvarID = LEDprodvars.LEDprodvarID WHERE LEDprodvars.LEDprodvarname = 'Colour' AND LEDprodoptions.LEDprodoptionsID = %s AND LEDprodoptions.LEDid = %s", GetSQLValueString($paramOption_rsCOLOURLOOKUP, "int"),GetSQLValueString($paramItem_rsCOLOURLOOKUP, "int"));
$rsCOLOURLOOKUP = mysql_query($query_rsCOLOURLOOKUP, $njMySQL) or die(mysql_error());
$row_rsCOLOURLOOKUP = mysql_fetch_assoc($rsCOLOURLOOKUP);
$totalRows_rsCOLOURLOOKUP = mysql_num_rows($rsCOLOURLOOKUP);

$paramItem_rsSENSOR = "-1";
if (isset($row_rsPROD['LEDid'])) {
$paramItem_rsSENSOR = $row_rsPROD['LEDid'];
}
mysql_select_db($database_njMySQL, $njMySQL);
$query_rsSENSOR = sprintf("SELECT LEDprodoptions.LEDprodoptionincr, LEDprodoptions.LEDprodoptionsID, LEDvars.LEDvarname, LEDvars.LEDprodvarID, LEDprodvars.LEDprodvarname FROM LEDvars INNER JOIN LEDprodoptions ON LEDvars.LEDvarID = LEDprodoptions.LEDvarID INNER JOIN LEDprodvars ON LEDvars.LEDprodvarID = LEDprodvars.LEDprodvarID WHERE LEDprodvars.LEDprodvarname = 'Sensor' AND LEDprodoptions.LEDid = %s", GetSQLValueString($paramItem_rsSENSOR, "int"));
$rsSENSOR = mysql_query($query_rsSENSOR, $njMySQL) or die(mysql_error());
$row_rsSENSOR = mysql_fetch_assoc($rsSENSOR);
$totalRows_rsSENSOR = mysql_num_rows($rsSENSOR);

$paramOption_rsSENSORLOOKUP = "-1";
if (isset($_POST['LEDCart_1_Sensor_Add'])) {
$paramOption_rsSENSORLOOKUP = $_POST['LEDCart_1_Sensor_Add'];
}
$paramItem_rsSENSORLOOKUP = "-1";
if (isset($_POST['LEDCart_1_ID_Add'])) {
$paramItem_rsSENSORLOOKUP = $_POST['LEDCart_1_ID_Add'];
}
mysql_select_db($database_njMySQL, $njMySQL);
$query_rsSENSORLOOKUP = sprintf("SELECT LEDprodoptions.LEDprodoptionincr, LEDprodoptions.LEDprodoptionsID, LEDvars.LEDvarname, LEDvars.LEDprodvarID, LEDprodvars.LEDprodvarname FROM LEDvars INNER JOIN LEDprodoptions ON LEDvars.LEDvarID = LEDprodoptions.LEDvarID INNER JOIN LEDprodvars ON LEDvars.LEDprodvarID = LEDprodvars.LEDprodvarID WHERE LEDprodvars.LEDprodvarname = 'Sensor' AND LEDprodoptions.LEDprodoptionsID = %s AND LEDprodoptions.LEDid = %s", GetSQLValueString($paramOption_rsSENSORLOOKUP, "int"),GetSQLValueString($paramItem_rsSENSORLOOKUP, "int"));
$rsSENSORLOOKUP = mysql_query($query_rsSENSORLOOKUP, $njMySQL) or die(mysql_error());
$row_rsSENSORLOOKUP = mysql_fetch_assoc($rsSENSORLOOKUP);
$totalRows_rsSENSORLOOKUP = mysql_num_rows($rsSENSORLOOKUP);
?>
<?php
// WA eCart AddToCart
if (isset($_POST["LEDCart_1_ATC"]) || isset($_POST["LEDCart_1_ATC_x"])) {
$ATC_itemID = $_POST["LEDCart_1_ID_Add"];
$ATC_AddIfIn = 0;
$ATC_RedirectAfter = "shopping-basket.php";
$ATC_RedirectIfIn = "";
if (isset($totalRows_rsPROD) && $totalRows_rsPROD > 0) {
$row_rsPROD = WAEC_findRecordMySQL($rsPROD, "LEDid", $ATC_itemID);
if ($row_rsPROD) {
$ATC_itemName = "".$row_rsPROD['LEDproductcode'] ."";// column binding
$ATC_itemDescription = "".$row_rsPROD['LEDtitle'] ."";// column binding
$ATC_itemThumbnail = "".$row_rsPROD['LEDimg'] ."";// column binding
$ATC_itemWeight = floatval("".$row_rsPROD['LEDnetweight'] ."");// column binding
$ATC_itemQuantity = "".$_POST["LEDCart_1_Quantity_Add"] ."";// column binding
$ATC_itemPrice = floatval("".$row_rsPROD['LEDprice'] ."");// column binding
$ATC_itemColour = "".$_POST["LEDCart_1_Colour_Add"] ."";// column binding
$ATC_itemDimmable = "".$row_rsDIMMLOOKUP['LEDvarname'] ."";// column binding
$ATC_itemDimmPriceInc = floatval("".$row_rsDIMMLOOKUP['LEDprodoptionincr'] ."");// column binding
$ATC_itemSensor = "".$_POST["LEDCart_1_Sensor_Add"] ."";// column binding
mysql_data_seek($rsPROD, 0);
$row_rsPROD = mysql_fetch_assoc($rsPROD);
}
}
$ATC_itemQuantity = floatval($ATC_itemQuantity);
if (is_numeric($ATC_itemQuantity) && $ATC_itemQuantity != 0) {
$LEDCart->AddToCart($ATC_AddIfIn, $ATC_RedirectIfIn, $ATC_itemID, $ATC_itemName, $ATC_itemDescription, $ATC_itemThumbnail, $ATC_itemWeight, $ATC_itemQuantity, $ATC_itemPrice, $ATC_itemColour, $ATC_itemDimmable, $ATC_itemDimmPriceInc, $ATC_itemSensor);
if ($ATC_RedirectAfter != "" && $LEDCart->redirStr == "") {
$LEDCart->redirStr = $ATC_RedirectAfter;
}
if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != "") {
$_SESSION['WAEC_ContinueRedirect'] = $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'];
}
else {
$_SESSION['WAEC_ContinueRedirect'] = $_SERVER['PHP_SELF'];
}
}
}
?>
<?php
// WA eCart Redirect
if ($LEDCart->redirStr != "") {
header("Location: ".$LEDCart->redirStr);
}
?>

Can someone help me make sense of (strip down!) the above and also explain why eCart is inserting duplicate content like this?

With ASP/VBScript I had a reasonable understanding of what all this meant but I'm terrified of changing anything in the PHP for fear of wrecking a script.

Thank you.
NJ

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...