I'm implementing a shopping cart but am having a problem in checking out a person who has added item in his/her shopping busket.The code for the checkout.php script is given below
<?
require_once('functions.inc.php');
session_start();
do_html_header("Checkout");
$cart = $_SESSION['cart'];
if($cart&&array_count_values($cart))
{
display_cart($cart,false,0);
display_checkout_form($HTTP_POST_VARS);
}
else
echo"<p>There are no items in your cart";
do_html_url("index.php","Continue Shopping");
?>
After a person has added vehicles to his/her cart and now wants to checkout, the checkout.php script generates this error:
'There are no items in your cart Continue Shopping :PHP Warning: array_count_values() [function.array-count-values]: The argument should be an array in C:\...shopping_cart\checkout.php on line 12' where line 12 is
if($cart&&array_count_values($cart))
I have realised that the code is not even reading whether or not a person has added something in his/her cart , but don't no where the error is.
The fucntions in the shopping cart are found in the function.inc below:
function.inc
<?php
$table_width = '995';
function do_html_header($title = '')
{
// print an HTML header including cute logo :)
global $table_width;
?>
<html>
<head>
<title><?php echo $title?></title>
</head>
<body>
<table width = <?php echo $table_width?> cellspacing = 0 cellpadding = 6>
<tr>
<td bgcolor = "#0066CC" width = 110>
</td><td bgcolor = "#0066CC">
<h1><?php echo $title?></h1></td>
</tr>
</table>
<?php
}
function do_html_url ($url, $title) {
?>
<a href="<?=$url?>"><?=$title?></a>
<?
}
function writeShoppingCart() {
$cart = $_SESSION['cart'];
if (!$cart) {
return '<p>You have no items in your shopping cart</p>';
} else {
// Parse the cart session variable
$items = explode(',',$cart);
$s = (count($items) > 1) ? 's':'';
return '<p>You have <a href="cart.php">'.count($items).' item'.$s.' in your shopping cart</a></p>';
}
}
function showCart() {
global $db;
$cart = $_SESSION['cart'];
if ($cart) {
$items = explode(',',$cart);
$contents = array();
foreach ($items as $item) {
$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
}
$output[] = '<form action="cart.php?action=update" method="post" id="cart">';
$output[] = '<table>';
foreach ($contents as $id=>$qty) {
$sql = 'SELECT * FROM vehicles WHERE id = '.$id;
$result = $db->query($sql);
$row = $result->fetch();
extract($row);
$output[] = '<tr>';
$output[] = '<td><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>';
$output[] = '<td>'.$model.' '.$make.'</td>';
$output[] = '<td>Z$'.$price.'</td>';
$output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>';
$output[] = '<td>Z$'.($price * $qty).'</td>';
$total += $price * $qty;
$output[] = '</tr>';
}
$output[] = '</table>';
$output[] = '<p>Grand total: <strong>Z$'.$total.'</strong></p>';
$output[] = '<div><button type="submit">Update cart</button></div>';
$output[] = '</form>';
} else {
$output[] = '<p>You shopping cart is empty.</p>';
}
return join('',$output);
}
?>
your help is greatly appreciated
1 7246
I'm implementing a shopping cart but am having a problem in checking out a person who has added item in his/her shopping busket.The code for the checkout.php script is given below -
<?
-
require_once('functions.inc.php');
-
session_start();
-
do_html_header("Checkout");
-
$cart = $_SESSION['cart'];
-
if($cart&&array_count_values($cart))
-
{
-
display_cart($cart,false,0);
-
display_checkout_form($HTTP_POST_VARS);
-
}
-
else
-
echo"<p>There are no items in your cart";
-
do_html_url("index.php","Continue Shopping");
-
?>
-
After a person has added vehicles to his/her cart and now wants to checkout, the checkout.php script generates this error:
'There are no items in your cart Continue Shopping :PHP Warning: array_count_values() [function.array-count-values]: The argument should be an array in C:\...shopping_cart\checkout.php on line 12' where line 12 is
if($cart&&array_count_values($cart))
I have realised that the code is not even reading whether or not a person has added something in his/her cart , but don't no where the error is.
The fucntions in the shopping cart are found in the function.inc below:
function.inc -
<?php
-
$table_width = '995';
-
function do_html_header($title = '')
-
{
-
// print an HTML header including cute logo :)
-
-
global $table_width;
-
?>
-
<html>
-
<head>
-
<title><?php echo $title?></title>
-
</head>
-
<body>
-
-
<table width = <?php echo $table_width?> cellspacing = 0 cellpadding = 6>
-
<tr>
-
<td bgcolor = "#0066CC" width = 110>
-
</td><td bgcolor = "#0066CC">
-
<h1><?php echo $title?></h1></td>
-
</tr>
-
</table>
-
-
<?php
-
}
-
-
function do_html_url ($url, $title) {
-
?>
-
<a href="<?=$url?>"><?=$title?></a>
-
<?
-
}
-
-
function writeShoppingCart() {
-
-
$cart = $_SESSION['cart'];
-
if (!$cart) {
-
return '<p>You have no items in your shopping cart</p>';
-
} else {
-
// Parse the cart session variable
-
$items = explode(',',$cart);
-
$s = (count($items) > 1) ? 's':'';
-
return '<p>You have <a href="cart.php">'.count($items).' item'.$s.' in your shopping cart</a></p>';
-
}
-
}
-
-
function showCart() {
-
global $db;
-
$cart = $_SESSION['cart'];
-
if ($cart) {
-
$items = explode(',',$cart);
-
$contents = array();
-
foreach ($items as $item) {
-
$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
-
}
-
$output[] = '<form action="cart.php?action=update" method="post" id="cart">';
-
$output[] = '<table>';
-
foreach ($contents as $id=>$qty) {
-
$sql = 'SELECT * FROM vehicles WHERE id = '.$id;
-
$result = $db->query($sql);
-
$row = $result->fetch();
-
extract($row);
-
$output[] = '<tr>';
-
$output[] = '<td><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>';
-
$output[] = '<td>'.$model.' '.$make.'</td>';
-
$output[] = '<td>Z$'.$price.'</td>';
-
$output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>';
-
$output[] = '<td>Z$'.($price * $qty).'</td>';
-
$total += $price * $qty;
-
$output[] = '</tr>';
-
}
-
$output[] = '</table>';
-
$output[] = '<p>Grand total: <strong>Z$'.$total.'</strong></p>';
-
$output[] = '<div><button type="submit">Update cart</button></div>';
-
$output[] = '</form>';
-
} else {
-
$output[] = '<p>You shopping cart is empty.</p>';
-
}
-
return join('',$output);
-
}
-
?>
-
your help is greatly appreciated
You need to ensure that the items in the cart are actually there.
If your view cart is working then it is not carrying over to the checkout.
You can also check to see that the items are stored within the array. I recently used the below script to find an error in one of my scripts. -
function show_array($array) {
-
foreach ($array as $value) {
-
if (is_array($value)) {
-
show_array($value);
-
} else {
-
echo $value . "<br>";
-
}
-
}
-
}
-
-
show_array($array);
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Robert |
last post by:
Hello all..
Im a beginner in php and looking to do something similar to a shopping
cart system. I want users to be able to view profiles on people and
be able to add them to the "shopping cart"...
|
by: Erik |
last post by:
Does anybody know of a free ASP shopping cart or some free ASP code to help
someone get a shopping cart started. Or does anybody have any experience
using a ASP shopping cart that is inexpensive...
|
by: Don Grover |
last post by:
I am retrieving costs and product id's from a sql db. and need to build a
shopping cart around it.
How do I store the selected items and qty req so I can move into another
catalog and total up as...
|
by: Paul Bruneau |
last post by:
Hi,
I hope someone can help me make a working shopping cart, as a learning tool.
If I have a "Product Demo" html page with a "Buy Me" button, there must be
a simple javascript method of...
|
by: madison |
last post by:
Hi,
I am trying to start a website using paypals shopping cart function.
If i have 10 items and they sell out, how do I make it so the item is
then listed as sold out. The next person would not...
|
by: VM |
last post by:
I'm interested in creating a simple shopping cart in C#. Are there sites
that show you, step by step, how to create a simple cart? The sites I've
found only show you pre-made shopping carts that...
|
by: Guadala Harry |
last post by:
I'm looking to implement some *minimal* shopping cart. I've looked at a few
3rd party packages, and they're all way too involved for what I need. So,
I'm thinking it might make sense to roll my...
|
by: G.E.M.P |
last post by:
High Level Session Handling Design for a Shopping cart
0) What am I missing?
1) How does OSCommerce do it?
I'm thinking about building a shopping cart from scratch,
using a library of dynamic...
|
by: frank |
last post by:
can anyone point me to a free shopping-cart script?
|
by: BenKen |
last post by:
Hi all pls I'm having great difficulty in making my shopping cart work. I am a newbie in php with little understanding of it. Add to cart button doesn't work and shopping cart in general doesn't. Pls...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |