Thankyou for your time dalecosp, most appreciated.
Still no cigar 🙂 I'll try and give you a few more details.
I have a page (called genre.php) which lists all the movie titles for that genre.
If the customer clicks the "add to Cart" button:
<form action="cart/addtocart.php" method="post">
<INPUT name="image2" type=image src="images/add_to_cart_btn.gif" alt="Add to Cart" border=0>
<input name="movie_id" type="hidden" value="<? echo $movie_id ?>">
</form>
the $movie_id variable is sent to the addtocart.php script.
here is the code for addtocart.php:
<?php
ob_start();
include ('functions.php');
session_start();
if (!empty($_POST['movie_id'])) {
// Really should do some checking here because otherwise people can just
// enter stuff in from the url and cause no end of problems
$movie_id = $_POST['movie_id'];
// Starting a new cart session
if (!session_is_registered("cart")) {
$_SESSION['cart'] = array();
$_SESSION['items'] = 0;
$_SESSION['total_price'] = 0.00;
}
// Existing book in the cart + 1
if (!isset($_SESSION['cart'][$movie_id])) {
$_SESSION['cart'][$movie_id]++;
}
else {
$_SESSION['cart'][$movie_id] = 1;
}
$_SESSION['total_price'] = calculate_price($_SESSION['cart']);
$_SESSION['items'] = calculate_items ($_SESSION['cart']);
header ("Location: ./");
}
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
</body>
</html>
<?
ob_end_flush();
?>
the include file functions.php looks like:
<?PHP
function calculate_price($cart)
{
$_SESSION['price']=0.0;
if(is_array($_SESSION['cart']))
{
$connection=mysql_connect("localhost","","") or die('Could not connect to the database server');
$db = mysql_select_db("swiftflix_sell", $connection) or die ("Unable to select database.");
foreach($_SESSION['cart'] as $isbn => $qty)
{
$sql= "SELECT
movie_current_price
FROM
movie_status
WHERE
movie_id='$isbn'";
$sql_result = mysql_query($sql,$connection) or die ("Could not select data");
while ($row = mysql_fetch_row($sql_result))
{
$_SESSION['movie_current_price']= $row['0'];
}
$_SESSION['price'] += $_SESSION['movie_current_price']*$qty;
}
}
return $_SESSION['price'];
}
function calculate_items($cart)
{
$_SESSION['items']=0;
if(is_array($_SESSION['cart']))
{
foreach($_SESSION['cart'] as $movie_id => $qty)
{
$_SESSION['items'] += $qty;
}
}
return $_SESSION['items'];
}
?>
When the addtocart.php script has done its thing the following header() is exected:
header ("Location: ./")
This goes to the page index.php which contains the code from the previous posts. The variables get sent on my local server but not my remote server.
I hope that explains it a little better. Can you see any areas that look out of place?
Cheers once again,
micmac