Jump to content

Custom PHP CMS/Cart 'add product' issue


bigdawg723

Recommended Posts

Hello All,

 

Well... my designer/developer won't respond. The site was designed... he added all my products for me... now when I try to go in to add a product... nothing happens.

 

I get the add product screen with all of the input fields... but when I click on the submit button labeled "Add Product"... nothing happens.

 

I have strong HTML skills... but limited PHP knowledge. I can post any source code needed here. It seems like it's a very simple issue... as all of the code seems to be there... I just don't know what to look for!

 

Here's the form code on the page where I input all of the product info:

<form action="processProduct.php?action=addProduct" method="post" enctype="multipart/form-data" name="frmAddProduct" id="frmAddProduct">

 

...and here's the code for the submit button:

<input name="btnAddProduct" type="button" id="btnAddProduct" value="Add Product" onClick="checkAddProductForm();" class="box">

 

Any and all advice GREATLY appreciated!

 

I hope someone can help me.

Link to comment
https://forums.phpfreaks.com/topic/197706-custom-php-cmscart-add-product-issue/
Share on other sites

There's two possibilities as far as I can tell. Either the checkAddProductForm function is not working correctly, otherwise there is an issue on your processproduct.php page, but if you're clicking the button and it never REACHES the processProduct.php page, it's almost guaranteed to be an issue with the checkAddProductForm script.

 

 

Look on the page the button is on for anything that says something similar to:

 

include("checkAddProductForm.php") or look in between the <head> tags and see if the script itself is there.

 

Otherwise, it could be included in any other file that is included.

 

If it's not right on that page, open all the pages that are "included" and try and find the script.

 

Should look like:

<script language="JavaScript">

function checkProductAddForm()

{

... etc.

 

It's not returning an error or it's hung up on something.

 

All of this is just a guess though, but that's where I'd start looking anyhow.

 

There's a JS file linked in the header... here's the header code from the add product page:

<script language="JavaScript" type="text/javascript" src="http://www.firebellylawncare.com/admin/library/product.js"></script>

 

Now here's the function from that product.js page:

function checkAddProductForm()
{
with (window.document.frmAddProduct) {
	if (cboCategory.selectedIndex == 0) {
		alert('Choose the product category');
		cboCategory.focus();
		return;
	} else if (isEmpty(txtName, 'Enter Product name')) {
		return;
	} else {
		submit();
	}
}
}

 

Does that help at all?

Oh, and this is all of the code from the processProduct.php page. Man I hope there's something obviously broken that you see in this whole 'adding products' process.

 

<?php
require_once '../../library/config.php';
require_once '../library/functions.php';

checkUser();

$action = isset($_GET['action']) ? $_GET['action'] : '';

switch ($action) {

case 'addProduct' :
	addProduct();
	break;

case 'modifyProduct' :
	modifyProduct();
	break;

case 'deleteProduct' :
	deleteProduct();
	break;

case 'deleteImage' :
	deleteImage();
	break;

case 'addOffert' :
	addOffert();
	break;

case 'modifyOffer' :
	modifyOffer();
	break;
    

default :
    // if action is not defined or unknown
	// move to main product page
	header('Location: index.php');
}


function addProduct()
{
    $catId       = $_POST['cboCategory'];
$sku = $_POST['txtSku'];
    $name        = $_POST['txtName'];
$description = $_POST['mtxDescription'];
$direction = $_POST['txtDirection'];
$benefits = $_POST['txtBenefites'];
$size1 = $_POST['txtSize1'];
$coverage1 = $_POST['txtCoverage1'];
$price1       = str_replace(',', '', (double)$_POST['txtPrice1']);
$qty1         = (int)$_POST['txtQty1'];
$size2 = $_POST['txtSize2'];
$coverage2 = $_POST['txtCoverage2'];
$price2       = str_replace(',', '', (double)$_POST['txtPrice2']);
$qty2         = (int)$_POST['txtQty2'];
$size3 = $_POST['txtSize3'];
$coverage3 = $_POST['txtCoverage3'];
$price3       = str_replace(',', '', (double)$_POST['txtPrice3']);
$qty3         = (int)$_POST['txtQty3'];
if(!empty($_POST['txtSize4'])) {
	$size4 = $_POST['txtSize4'];
} else {
	$size4 = '';
}
if(!empty($_POST['txtCoverage4'])) {
	$coverage4 = $_POST['txtCoverage4'];
} else {
	$coverage4 = '';
}
if(!empty($_POST['txtPrice4'])) {
	$price4       = str_replace(',', '', (double)$_POST['txtPrice4']);
} else {
	$price4       = '';
}
if(!empty($_POST['txtQty4'])) {
	$qty4         = (int)$_POST['txtQty4'];
} else {
	$qty4         = '';
}
if(!empty($_POST['txtSize5'])) {
	$size5 = $_POST['txtSize5'];
} else {
	$size5 = '';
}
if(!empty($_POST['txtCoverage5'])) {
	$coverage5 = $_POST['txtCoverage5'];
} else {
	$coverage5 = '';
}
if(!empty($_POST['txtPrice5'])) {
	$price5       = str_replace(',', '', (double)$_POST['txtPrice5']);
} else {
	$price5       = '';
}
if(!empty($_POST['txtQty5'])) {
	$qty5         = (int)$_POST['txtQty5'];
} else {
	$qty5         = '';
}

$shipWithIn = $_POST['txtShipWithin'];


$images = uploadProductImage('fleImage', SRV_ROOT . 'images/product/');

$mainImage = $images['image'];
$thumbnail = $images['thumbnail'];

$sql   = "INSERT INTO tbl_product (cat_id, pd_sku, pd_name, pd_description, pd_direction, pd_benefits, pd_size1, pd_coverage1,  pd_price1, pd_qty1, pd_size2, pd_coverage2,  pd_price2, pd_qty2, pd_size3, pd_coverage3,  pd_price3, pd_qty3, pd_size4, pd_coverage4,  pd_price4, pd_qty4, pd_size5, pd_coverage5,  pd_price5, pd_qty5, pd_shipwithin, pd_image, pd_thumbnail, pd_date)
          VALUES ('$catId', '$sku', '$name', '$description', '$direction', '$benefits', '$size1', '$coverage1', $price1, '$qty1', '$size2', '$coverage2', $price2, '$qty2', '$size3', '$coverage3', $price3, '$qty3', '$size4', '$coverage4', $price4, '$qty4','$size5', '$coverage5', $price5, '$qty5','$shipWithIn', '$mainImage', '$thumbnail', NOW())";

$result = dbQuery($sql);

header("Location: index.php");	
}

/*
Upload an image and return the uploaded image name 
*/
function uploadProductImage($inputName, $uploadDir)
{
$image     = $_FILES[$inputName];
$imagePath = '';
$thumbnailPath = '';

// if a file is given
if (trim($image['tmp_name']) != '') {
	$ext = substr(strrchr($image['name'], "."), 1); //$extensions[$image['type']];

	// generate a random new file name to avoid name conflict
	$imagePath = md5(rand() * time()) . ".$ext";

	list($width, $height, $type, $attr) = getimagesize($image['tmp_name']); 

	// make sure the image width does not exceed the
	// maximum allowed width
	if (LIMIT_PRODUCT_WIDTH && $width > MAX_PRODUCT_IMAGE_WIDTH) {
		$result    = createThumbnail($image['tmp_name'], $uploadDir . $imagePath, MAX_PRODUCT_IMAGE_WIDTH);
		$imagePath = $result;
	} else {
		$result = move_uploaded_file($image['tmp_name'], $uploadDir . $imagePath);
	}	

	if ($result) {
		// create thumbnail
		$thumbnailPath =  md5(rand() * time()) . ".$ext";
		$result = createThumbnail($uploadDir . $imagePath, $uploadDir . $thumbnailPath, THUMBNAIL_WIDTH);

		// create thumbnail failed, delete the image
		if (!$result) {
			unlink($uploadDir . $imagePath);
			$imagePath = $thumbnailPath = '';
		} else {
			$thumbnailPath = $result;
		}	
	} else {
		// the product cannot be upload / resized
		$imagePath = $thumbnailPath = '';
	}

}


return array('image' => $imagePath, 'thumbnail' => $thumbnailPath);
}

/*
Modify a product
*/
function modifyProduct()
{
$proId = (int)$_GET['productId'];
$catId       = $_POST['cboCategory'];
$sku = $_POST['txtSku'];
    $name        = $_POST['txtName'];
$description = $_POST['mtxDescription'];
$direction = $_POST['txtDirection'];
$benefits = $_POST['txtBenefites'];
$size1 = $_POST['txtSize1'];
$coverage1 = $_POST['txtCoverage1'];
$price1       = str_replace(',', '', (double)$_POST['txtPrice1']);
$qty1         = (int)$_POST['txtQty1'];
$size2 = $_POST['txtSize2'];
$coverage2 = $_POST['txtCoverage2'];
$price2       = str_replace(',', '', (double)$_POST['txtPrice2']);
$qty2         = (int)$_POST['txtQty2'];
$size3 = $_POST['txtSize3'];
$coverage3 = $_POST['txtCoverage3'];
$price3       = str_replace(',', '', (double)$_POST['txtPrice3']);
$qty3         = (int)$_POST['txtQty3'];
if(!empty($_POST['txtSize4'])) {
	$size4 = $_POST['txtSize4'];
} else {
	$size4 = '';
}
if(!empty($_POST['txtCoverage4'])) {
	$coverage4 = $_POST['txtCoverage4'];
} else {
	$coverage4 = '';
}
if(!empty($_POST['txtPrice4'])) {
	$price4       = str_replace(',', '', (double)$_POST['txtPrice4']);
} else {
	$price4       = '';
}
if(!empty($_POST['txtQty4'])) {
	$qty4         = (int)$_POST['txtQty4'];
} else {
	$qty4         = '';
}
if(!empty($_POST['txtSize5'])) {
	$size5 = $_POST['txtSize5'];
} else {
	$size5 = '';
}
if(!empty($_POST['txtCoverage5'])) {
	$coverage5 = $_POST['txtCoverage5'];
} else {
	$coverage5 = '';
}
if(!empty($_POST['txtPrice5'])) {
	$price5       = str_replace(',', '', (double)$_POST['txtPrice5']);
} else {
	$price5       = '';
}
if(!empty($_POST['txtQty5'])) {
	$qty5         = (int)$_POST['txtQty5'];
} else {
	$qty5         = '';
}

$shipWithIn = $_POST['txtShipWithin'];


$images = uploadProductImage('fleImage', SRV_ROOT . 'images/product/');

$mainImage = $images['image'];
$thumbnail = $images['thumbnail'];

// if uploading a new image
// remove old image
if ($mainImage != '') {
	_deleteImage($proId);

	$mainImage = "'$mainImage'";
	$thumbnail = "'$thumbnail'";
} else {
	// if we're not updating the image
	// make sure the old path remain the same
	// in the database
	$mainImage = 'pd_image';
	$thumbnail = 'pd_thumbnail';
}

$sql   = "UPDATE tbl_product 
          SET cat_id = '$catId', pd_sku = '$sku', pd_name = '$name', pd_description = '$description', pd_direction = '$direction', pd_benefits = '$benefits', pd_size1 = '$size1', pd_coverage1 = '$coverage1', pd_price1 = '$price1', pd_qty1 = '$qty1', pd_size2 = '$size2', pd_coverage2 = '$coverage2', pd_price2 = '$price2', pd_qty2 = '$qty2', pd_size3 = '$size3', pd_coverage3 = '$coverage3', pd_price3 = '$price3', pd_qty3 = '$qty3', pd_size4 = '$size4', pd_coverage4 = '$coverage4',  pd_price4 = '$price4', pd_qty4 = '$qty4', pd_size5 = '$size5', pd_coverage5 = '$coverage5',  pd_price5 = '$price4', pd_qty5 = '$qty5', pd_image = $mainImage, pd_thumbnail = $thumbnail
		  WHERE pd_id = $proId";  

$result = dbQuery($sql);

header('Location: index.php');			  
}

/*
Remove a product
*/
function deleteProduct()
{
if (isset($_GET['productId']) && (int)$_GET['productId'] > 0) {
	$productId = (int)$_GET['productId'];
} else {
	header('Location: index.php');
}

// remove any references to this product from
// tbl_order_item and tbl_cart
$sql = "DELETE FROM tbl_order_item
        WHERE pd_id = $productId";
dbQuery($sql);

$sql = "DELETE FROM tbl_cart
        WHERE pd_id = $productId";	
dbQuery($sql);

// get the image name and thumbnail
$sql = "SELECT pd_image, pd_thumbnail
        FROM tbl_product
		WHERE pd_id = $productId";

$result = dbQuery($sql);
$row    = dbFetchAssoc($result);

// remove the product image and thumbnail
if ($row['pd_image']) {
	unlink(SRV_ROOT . 'images/product/' . $row['pd_image']);
	unlink(SRV_ROOT . 'images/product/' . $row['pd_thumbnail']);
}

// remove the product from database;
$sql = "DELETE FROM tbl_product 
        WHERE pd_id = $productId";
dbQuery($sql);

header('Location: index.php?catId=' . $_GET['catId']);
}


/*
Remove a product image
*/
function deleteImage()
{
if (isset($_GET['productId']) && (int)$_GET['productId'] > 0) {
	$productId = (int)$_GET['productId'];
} else {
	header('Location: index.php');
}

$deleted = _deleteImage($productId);

// update the image and thumbnail name in the database
$sql = "UPDATE tbl_product
		SET pd_image = '', pd_thumbnail = ''
		WHERE pd_id = $productId";
dbQuery($sql);		

header("Location: index.php?view=modify&productId=$productId");
}

function _deleteImage($productId)
{
// we will return the status
// whether the image deleted successfully
$deleted = false;

$sql = "SELECT pd_image, pd_thumbnail 
        FROM tbl_product
		WHERE pd_id = $productId";
$result = dbQuery($sql) or die('Cannot delete product image. ' . mysql_error());

if (dbNumRows($result)) {
	$row = dbFetchAssoc($result);
	extract($row);

	if ($pd_image && $pd_thumbnail) {
		// remove the image file
		$deleted = @unlink(SRV_ROOT . "images/product/$pd_image");
		$deleted = @unlink(SRV_ROOT . "images/product/$pd_thumbnail");
	}
}

return $deleted;
}


function addOffert() {
$pdId = (int)$_GET['offId'];
$offerAmount = $_POST['offerAmount'];
$offDescription = $_POST['description'];

$sql = "UPDATE tbl_product SET pd_offer_amount = '$offerAmount', pd_offer_description = '$offDescription' WHERE pd_id = '$pdId'";
$result = dbQuery($sql);
header("Location:index.php");

}

function modifyOffer() {
$pdId = (int)$_GET['offId'];
$offerAmount = $_POST['offerAmount'];
$offDescription = $_POST['description'];

$sql = "UPDATE tbl_product SET pd_offer_amount = '$offerAmount', pd_offer_description = '$offDescription' WHERE pd_id = '$pdId'";
$result = dbQuery($sql);
header("Location:index.php");

}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.