I am a beginner in php. As the matter of fact, i could not debug the following code about a shopping which i downloaded. I tried running but could not add items to the shopping cart.
file name: product-functions.php
<?php
require_once 'config.php';
/*********************************************************
* PRODUCT FUNCTIONS
**********************************************************/
/*
Get detail information of a product
*/
function getProductDetail($pdId, $catId)
{
$_SESSION['shoppingReturnUrl'] = $_SERVER['REQUEST_URI'];
// get the product information from database
$sql = "SELECT pd_name, pd_description, pd_price, pd_image, pd_qty
FROM tbl_product
WHERE pd_id = $pdId";
$result =mysql_query($sql);
$row = mysql_fetch_assoc($result);
extract($row);
$row['pd_description'] = nl2br($row['pd_description']);
if ($row['pd_image']) {
$row['pd_image'] = WEB_ROOT . 'images/product/' . $row['pd_image'];
} else {
$row['pd_image'] = WEB_ROOT . 'images/no-image-large.png';
}
$row['cart_url'] = "cart.php?action=add&p=$pdId";
return $row;
}
?>
and the other file is productDetail.php
<?php
if (!defined('WEB_ROOT')) {
exit;
}
$product = getProductDetail($pdId, $catId);
// we have $pd_name, $pd_price, $pd_description, $pd_image, $cart_url
extract($product);
?>
<table width="100%" border="0" cellspacing="0" cellpadding="10">
<tr>
<td align="center"><img src="<?php echo $pd_image; ?>" border="0" alt="<?php echo $pd_name; ?>"></td>
<td valign="middle">
<strong><?php echo $pd_name; ?></strong><br>
Price : <?php echo displayAmount($pd_price); ?><br>
<?php
// if we still have this product in stock
// show the 'Add to cart' button
if ($pd_qty > 0) {
?>
<input type="button" name="btnAddToCart" value="Add To Cart >" onClick="window.location.href='<?php echo $cart_url; ?>';" class="addToCartButton">
<?php
} else {
echo 'Out Of Stock';
}
?>
</td>
</tr>
<tr align="left">
<td colspan="2"><?php echo $pd_description; ?></td>
</tr>
</table>
The errors that i am getting are:
code Warning: extract() expects parameter 1 to be array, boolean given in C:\wamp\www\plaincart\library\product-functions.php on line 25
Call Stack
Time Memory Function Location
1 0.0005 374752 {main}( ) ..\index.php:0
2 0.0234 546312 require_once( 'C:\wamp\www\plaincart\include\productDetail.php' ) ..\index.php:29
3 0.0234 546312 getProductDetail( ) ..\productDetail.php:10
4 0.0238 548576 extract ( ) ..\product-functions.php:25
( ! ) Notice: Undefined index: pd_image in C:\wamp\www\plaincart\library\product-functions.php on line 32
Call Stack
Time Memory Function Location
1 0.0005 374752 {main}( ) ..\index.php:0
2 0.0234 546312 require_once( 'C:\wamp\www\plaincart\include\productDetail.php' ) ..\index.php:29
3 0.0234 546312 getProductDetail( ) ..\productDetail.php:10
(
( ! ) Notice: Undefined variable: pd_name in C:\wamp\www\plaincart\include\productDetail.php on line 22
Call Stack
Time Memory Function Location
1 0.0005 374752 {main}( ) ..\index.php:0
2 0.0234 546312 require_once( 'C:\wamp\www\plaincart\include\productDetail.php' ) ..\index.php:29
Price :
( ! ) Notice: Undefined variable: pd_price in C:\wamp\www\plaincart\include\productDetail.php on line 23
Call Stack
Time Memory Function Location
1 0.0005 374752 {main}( ) ..\index.php:0
2 0.0234 546312 require_once( 'C:\wamp\www\plaincart\include\productDetail.php' ) ..\index.php:29
$0
( ! ) Notice: Undefined variable: pd_qty in C:\wamp\www\plaincart\include\productDetail.php on line 27
Call Stack
Time Memory Function Location
1 0.0005 374752 {main}( ) ..\index.php:0
2 0.0234 546312 require_once( 'C:\wamp\www\plaincart\include\productDetail.php' ) ..\index.php:29
Out Of Stock[/code]
So far i could not fix it. Please help me