In the following posted code(add products at admin side)

function addProduct()
    $catId       = $_POST['cboCategory'];
    $name        = $_POST['txtName'];
	$description = $_POST['mtxDescription'];
	$price       = str_replace(',', '', (double)$_POST['txtPrice']);
	$qty         = (int)$_POST['txtQty'];
	$images = uploadProductImage('fleImage', SRV_ROOT . 'images/product/');
echo $images;

	$mainImage = $images['image'];
	$thumbnail = $images['thumbnail'];
echo $mainimage;
echo $thumbnail;
	$sql   = "INSERT INTO tbl_product (cat_id, pd_name, pd_description, pd_price, pd_qty, pd_image, pd_thumbnail, pd_date)
	          VALUES ('$catId', '$name', '$description', $price, $qty, '$mainImage', '$thumbnail', NOW())";

	$result = dbQuery($sql);
	header("Location: index.php?catId=$catId");	

	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
			$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";
echo $thumbnailpath;
			$result = createThumbnail($uploadDir . $imagePath, $uploadDir . $thumbnailPath, THUMBNAIL_WIDTH);
echo $result;			
			// 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);

i inserted the following lines of code,
echo $images; at line 10
echo $mainimage; at line 14
echo $thumbnail; at line 15
echo $thumbnailpath; at line 56
echo $result; at line 58
to see the value stored in the respective variable at running the file.

i cannot see the values when running the file (this funtion is called when the admin enters the product name,product descrption etc.. in the add product form and click the 'add product' button in the form)

But i cannot see the values stored in those variables,i see only the normal output i.e list of products added by the admin
what are the correct codes..??

8 Years
Discussion Span
Last Post by Rkeast

The only reason you would not see anything when using echo to print the variable, would be if the variable has not been set, or it has no value.

Try something like:

echo isset($images);
echo is_null($images);

to see if you've declared the variable yet, or if it is null.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.