I have another problem.
I try to modify the plaincart and the problem is that the images doesn't show.
The code is this:

<?php
if (!defined('WEB_ROOT')) {
	exit;
}

$productsPerRow = 2;
$productsPerPage = 4;

//$productList    = getProductList($catId);
$children = array_merge(array($catId), getChildCategories(NULL, $catId));
$children = ' (' . implode(', ', $children) . ')';

$sql = "SELECT pd_id, pd_name, pd_price, pd_thumbnail, pd_qty, c.cat_id
		FROM tbl_product pd, tbl_category c
		WHERE pd.cat_id = c.cat_id AND pd.cat_id IN $children 
		ORDER BY pd_name";
$result     = dbQuery(getPagingQuery($sql, $productsPerPage));
$pagingLink = getPagingLink($sql, $productsPerPage, "c=$catId");
$numProduct = dbNumRows($result);

// the product images are arranged in a table. to make sure
// each image gets equal space set the cell width here
$columnWidth = (int)(100 / $productsPerRow);
?>
<table width="100%" border="0" cellspacing="0" cellpadding="20">
<?php 
if ($numProduct > 0 ) {

	$i = 0;
	while ($row = dbFetchAssoc($result)) {
	
		extract($row);
		if ($pd_thumbnail) {
			$pd_thumbnail = WEB_ROOT . 'images/product/' . $pd_thumbnail;
		} else {
			$pd_thumbnail = WEB_ROOT . 'images/no-image-small.png';
		}
	
		if ($i % $productsPerRow == 0) {
			echo '<tr>';
		}

		// format how we display the price
		$pd_price = displayAmount($pd_price);
		
		echo "<td width=\"$columnWidth%\" align=\"center\"><a href=\"" . $_SERVER['PHP_SELF'] . "?c=$catId&p=$pd_id" . "\"><img src=\"$pd_thumbnail\" border=\"0\"><br>$pd_name</a><br>Price : $pd_price";

		// if the product is no longer in stock, tell the customer
		if ($pd_qty <= 0) {
			echo "<br>Out Of Stock";
		}
		
		echo "</td>\r\n";
	
		if ($i % $productsPerRow == $productsPerRow - 1) {
			echo '</tr>';
		}
		
		$i += 1;
	}
	
	if ($i % $productsPerRow > 0) {
		echo '<td colspan="' . ($productsPerRow - ($i % $productsPerRow)) . '">&nbsp;</td>';
	}
	
} else {
?>
	<tr><td width="100%" align="center" valign="center">No products in this category</td></tr>
<?php	
}	
?>
</table>
<p align="center"><?php echo $pagingLink; ?></p>

My images are in the images/product/ folder. The other info about the products (also the image ) are taken from the database.

As far as I could see, the problem is in WEB_ROOT, because the link to the picture is this:

http://wathever.com/home/a369557/public_html/2/images/category/2a5d7eb60c1625144b3bd785bf70342c.jpg

When it should be:

http://www.whatever.com/2/images/category/2a5d7eb60c1625144b3bd785bf70342c.jpg

How can I fix this?
Thanks!

Yeah, something like that but that's just an example.
The link to the image should be:

http://www.example.com/2/images/category/2a5d7eb60c1625144b3bd785bf70342c.jpg

But instead the link to the picture is this:

http://example.com/home/a369557/public_html/2/images/category/2a5d7eb60c1625144b3bd785bf70342c.jpg

I suppose the problem is in these lines:

if ($pd_thumbnail) {
			$pd_thumbnail = WEB_ROOT . 'images/product/' . $pd_thumbnail;
		} else {
			$pd_thumbnail = WEB_ROOT . 'images/no-image-small.png';
		}

Especially in the WEB_ROOT because for some reason it gives wrong path to the file.

Try this... remove the last " / " in your

$pd_thumbnail = WEB_ROOT . 'images/product/' . $pd_thumbnail;

as I analyze your code here... it runs that the syntax of the last " / " will concatenate what ever the value of $pd_thumbnail which results to certain mistake by most programmers

and I have one thing on my mind for sure.... does that WEB_ROOT results as your folder name either?

well that could be a mistake too...

another is you did not put a slash after you concatenate the WEB_ROOT

hey may I know what's your purpose of including WEB_ROOT ?

because by default WEB_ROOT should be the web link and if you want to save it on a folder... you don't need already to include WEB_ROOT in your data path destination according to the regulations of IIS (Internet Information Services)

by the default demand as of PHP 3 or 4 it could be now saved this way

$pd_thumbnail =  'images/product/' . $pd_thumbnail; // <---default file destination handler

or if you want to include WEB_ROOT... it should be this way

$pd_thumbnail = WEB_ROOT. '/images/product/' . $pd_thumbnail;

you may try either on of these code :)

Well I tried your suggestion which I suppose is something like this:

if ($pd_thumbnail) {
			$pd_thumbnail = WEB_ROOT . '/images/product' . $pd_thumbnail;
		} else {
			$pd_thumbnail = WEB_ROOT . 'images/no-image-small.png';
		}

but didn't work.

So is there a way that it can remove this part of the link:

home/a369557/public_html

and so that the link will start from /2/....?

I tried both suggestions, but everything stays the same. Even if I delete the WEB_ROOT it path to the image stays the same.
Actually, I've tried not using WEB_ROOT even before I stared this thread, but no luck.
And I'm actually surprised how on the demo site of the plaincart everything looks OK.
http://www.phpwebcommerce.com/plaincart/index.php

since you just want to out put the image on screen try to add like this

$pd_thumbnail = WEB_ROOT . '/images/product/' . $pd_thumbnail;

I wonder if it is something in the if($pd_thumbnail) itself has a valid value the way you want it

I've tried it that way but it doesn't work.
Well as far as I could see, pd_thumbnail shows only in 3 places in the file and to me they all look ok.
Also the database seems ok.

Also I noticed that the web root is defined in the config.php which looks like this:

<?php
ini_set('display_errors', 'On');
//ob_start("ob_gzhandler");
error_reporting(E_ALL);

// start the session
session_start();

// database connection config
$dbHost = 'examplehost.com';
$dbUser = 'exampleuser';
$dbPass = 'examplepass';
$dbName = 'examplename';

// setting up the web root and server root for
// this shopping cart application
$thisFile = str_replace('\\', '/', __FILE__);
$docRoot = $_SERVER['DOCUMENT_ROOT'];

$webRoot  = str_replace(array($docRoot, 'library/config.php'), '', $thisFile);
$srvRoot  = str_replace('library/config.php', '', $thisFile);

define('WEB_ROOT', $webRoot);
define('SRV_ROOT', $srvRoot);

// these are the directories where we will store all
// category and product images
define('CATEGORY_IMAGE_DIR', 'images/category/');
define('PRODUCT_IMAGE_DIR',  'images/product/');

// some size limitation for the category
// and product images

// all category image width must not 
// exceed 75 pixels
define('MAX_CATEGORY_IMAGE_WIDTH', 75);

// do we need to limit the product image width?
// setting this value to 'true' is recommended
define('LIMIT_PRODUCT_WIDTH',     true);

// maximum width for all product image
define('MAX_PRODUCT_IMAGE_WIDTH', 300);

// the width for product thumbnail
define('THUMBNAIL_WIDTH',         75);

if (!get_magic_quotes_gpc()) {
	if (isset($_POST)) {
		foreach ($_POST as $key => $value) {
			$_POST[$key] =  trim(addslashes($value));
		}
	}
	
	if (isset($_GET)) {
		foreach ($_GET as $key => $value) {
			$_GET[$key] = trim(addslashes($value));
		}
	}	
}

// since all page will require a database access
// and the common library is also used by all
// it's logical to load these library here
require_once 'database.php';
require_once 'common.php';

// get the shop configuration ( name, addres, etc ), all page need it
$shopConfig = getShopConfig();
?>

as u post it. it doesn't have Web_Root but has webRoot so try to replace Web_Root with webRoot

hmmmif that's not the case. try to use mysql_fetch_array function instead of dbQuery

Nope, it didn't work. The interesting thing is, it doesn't work either with or without the WEB_ROOT.

then that could be unsolvable :(

Probably... But I'll give my best to solve it!

It is solved!
The problem was in the file in which are the category-functions.
I removed the WEB_ROOT and now my working code looks like this:

if ($cat_image) {
			$cat_image = '/2/images/category/' . $cat_image;
		} else {
			$cat_image = '/2/images/no-image-small.png';
		}

Thanks a lot for the assistance!:-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.