/    Sign up×
Community /Pin to ProfileBookmark

code for show cart total and items not working

Hey, now I have a new problem. Working on an existing site, I’m copying over codes and this code for the page that used to show the items in their cart and the total including shipping, is not working. Is the entire thing all screwed up? Does anyone know?

[code=php]<?php
function do_html_URL($url, $name)
{
?>
<a href=”<?php echo $url; ?>”><?php echo $name; ?></a><br />
<?php
}

function display_categories($cat_array)
{
if (!is_array($cat_array))
{
echo ‘No categories currently available<br />’;
return;
}
echo ‘<ul>’;
foreach ($cat_array as $row)
{
$url = ‘show_cat.php?catid=’.($row[‘catid’]);
$title = $row[‘catname’];
echo ‘<li>’;
do_html_url($url, $title);
}
echo ‘</ul>’;
echo ‘<hr />’;
}

function display_products($array)
{
if (!is_array($array))
{
echo ‘<p style=”font: 12px/150% Arial, Verdana;”>No products currently available in this category</p>’;
}
else
{
//create table
echo ‘<table width = “100%” border = “0” cellpadding=”0″ cellspacing=”0″ align = “center”>’;

//create a table row for each ergopad
$row_counter = 0;
foreach ($array as $row)
{
$url = ‘show_product.php?product_id=’.($row[‘product_id’]);

if ($row_counter != 1)
{
echo ‘<tr>’;
}

echo ‘<td style=”font: 12px Arial, Verdana; text-align: center; padding-bottom: 5px; padding-top: 15px; border: 1px solid #efefef;”>’;
if (@file_exists(‘images/’.$row[‘product_id’].’.gif’))
{
$title = ‘<img src=’images/’.($row[‘product_id’]).’.gif’ border=0>’;
do_html_url($url, $title);
}
else
{
echo ‘&nbsp;’;
}
echo ‘<br />’;
$title = $row[‘product_name’];
do_html_url($url, $title);

if($row_counter == 1)
{
echo ‘</tr>’;
$row_counter = 0;
}
else{
echo ‘</td>’;
$row_counter++;
}
}
echo ‘</table><br /><br />’;
}
}

function display_product_details($product)
{
// display all details about this product
if (is_array($product))
{
echo ‘<table><tr>’;
//display the picture if there is one
if (@file_exists(‘images/’.($product[‘product_id’]).’.gif’))
{
$size = GetImageSize(‘images/’.$product[‘product_id’].’.gif’);
if($size[0]>0 && $size[1]>0)
echo ‘<td><img src=’images/’.$product[‘product_id’].’.gif’ border=0 ‘.$size[3].’></td>’;
}
echo ‘<td><ul style=”font: 12px/150% Arial, Verdana;”>’;
echo ‘<b>’.$product[‘product_name’].'</b>’;
echo ‘<li><b>Stock Number:</b> ‘;
echo $product[‘product_id’];
echo ‘<li><b>Description:</b> ‘;
echo $product[‘description’];
echo ‘<li><b>Price:</b><br /> ‘;
echo $product[‘country_name’].”&nbsp;&nbsp;”;
echo number_format($product[‘price’], 2);
echo ‘</ul></td></tr></table>’;
echo ‘<hr /><br />’;
}
}

function display_shipping($shipping)
{
?>
<table border = “0” width = “100%” cellspacing = “0”>
<tr><td align = “left”>Shipping</td>
<td align = “right”>$<?php echo number_format($shipping, 2); ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>
<tr><th bgcolor=”#cccccc” align = “left”>TOTAL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
<th bgcolor=”#cccccc” align = “right”>$<?php echo number_format($shipping+$_SESSION[‘total_price’], 2); ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
</tr>
</table><br />
<?php
}

function display_cart($cart, $change = true, $images = 0)
{
// display items in shopping cart
// optionally allow changes (true or false)
// optionally include images (1 – yes, 0 – no)

echo ‘<table border = 0 width = 100% cellspacing = 0>
<form action = “show_cart.php” method = “post”>
<tr align = “center”><th colspan = ‘. (1+$images) .’ bgcolor=”#cccccc”>Item</th>
<th bgcolor=”#cccccc”>Price</th><th bgcolor=”#cccccc”>Quantity</th>
<th bgcolor=”#cccccc”>Total</th></tr>’;

//display each item as a table row
foreach ($cart as $product_id => $qty)
{
$product = get_product_details($product_id);
echo ‘<tr>’;
if($images ==true)
{
echo ‘<td align = left>’;
if (file_exists(“images/$product_id.gif”))
{
$size = GetImageSize(‘images/’.$product_id.’.gif’);
if($size[0]>0 && $size[1]>0)
{
echo ‘<img src=”images/’.$product_id.’.gif” border=0 ‘;
echo ‘width = ‘. $size[0]/3 .’ height = ‘ .$size[1]/3 . ‘>’;
}
}
else
echo ‘&nbsp;’;
echo ‘</td>’;
}
echo ‘<td align = center>’;
echo ‘<a href = “show_product.php?product_id=’.$product_id.'”>’.$product[‘description’].'</a>’;
echo ‘</td><td align = center>$’.number_format($product[‘price’], 2);
echo ‘</td><td align = center>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;’;
// if we allow changes, quantities are in text boxes
if ($change == true)
echo “<input type = text style = “text-align: right”; name = “$product_id” value = “$qty” size = 3>”;
else
echo $qty;
echo ‘</td><td align = center>$’.number_format($product[‘price’]*$qty,2).”</td></tr>n”;
}
// display total row
echo ‘<tr>
<th colspan = ‘. (2+$images) .” bgcolor=”#cccccc”>&nbsp;</td>
<th align = “center” bgcolor=”#cccccc”>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;”.$_SESSION[‘items’].”
</th>
<th align = “center” bgcolor=”#cccccc”>
$”.number_format($_SESSION[‘total_price’], 2).
‘</th>
</tr>’;
// display save change button
if($change == true)
{
echo ‘<tr>
<td colspan = ‘. (2+$images) .’>&nbsp;</td>
<td align = center>
<br />
<input type = “hidden” name = “save” value = “true”>
<input type = “image” src = “images/save-changes.jpg” border = 0 alt = “Save Changes”>
</td>
<td>&nbsp;</td>
</tr>’;
}
echo ‘</form></table>’;
}[/code]

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@bathurst_guyApr 10.2007 — Is PHP installed on the new server?

When you say "it's not working" can you be more specific?
Copy linkTweet thisAlerts:
@bathurst_guyApr 10.2007 — You are using session variables in the script - do you have a session_start() at the beginning of the script?
Copy linkTweet thisAlerts:
@htmlignorantauthorApr 10.2007 — It's on the same server, I'm just trying to redo some of the pages in the site and linking new ones. When I say not working, I mean that when I hit Preview in GoLive to view what the page will look like, all the code text just shows up as text at the top of the page. It does have a session start.
Copy linkTweet thisAlerts:
@bathurst_guyApr 10.2007 — well you actually need to preview it from a server, i dont have golive and dont know how it previews (does it create a temp file somewhere?) your better off just uploading it to the server then testing it via a browser
Copy linkTweet thisAlerts:
@bathurst_guyApr 10.2007 — Save the document as checkout[B].php [/B]

It is not being parsed by the php parser.
×

Success!

Help @htmlignorant spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...