hi everyone, fairly new to php and i am trying to complete a shopping basket on my site. I have got it working locally but as soon as i upload it to the remote version it stops working.
here is the error i get:
Warning: Cannot use a scalar value as an array in /home/nas03l/d/mysite.co.uk/user/htdocs/basket.php on line 24
Warning: Cannot use a scalar value as an array in /home/nas03l/d/mysite.co.uk/user/htdocs/basket.php on line 24
Warning: Cannot modify header information - headers already sent by (output started at /home/nas03l/d/mysite.co.uk/user/htdocs/basket.php:24) in /home/nas03l/d/mysite.co.uk/user/htdocs/basket.php on line 26
and here is the code for the basket page ( i have removed some of irrelevant code):
Code:
<?php
session_start();
if (!isset($_SESSION['cart']))
{
$_SESSION['cart'] = array();
}
if (!isset($_SESSION['addon']))
{
$_SESSION['addon'] = array();
}
if (isset($_POST['bid']))
{
$_SESSION['cart'][] = $_POST['bid'];
if (isset($_POST['addon']))
{
$addonarrays = $_POST['addon'];
}
else
{
$addonarrays = array();
}
foreach($addonarrays as $addonarray)
{
$_SESSION['addon'][] = $addonarray;
}
header('location: ' . $_SERVER['PHP_SELF'] . '?' . SID);
exit();
}
if (isset($_GET['empty']))
{
unset($_SESSION['cart']);
unset($_SESSION['addon']);
header('location: ' . $_SERVER['PHP_SELF'] . '?' . SID);
exit();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Basket</title>
<meta name="description" content="basket"/>
<meta name="keywords" content="basket"/>
<link href="styles1.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery-jqir.js"></script>
<script type="text/javascript">
$(document).ready(
function()
{
$(".jqir").jQIR("png", "pictures/");
}
);
</script>
</head>
<body>
<h1>Your Basket</h1>
<p>Your Basket Contains the following items:</p>
<?php
require ('databaseconnect.inc');
$productids = $_SESSION['cart'];
foreach ($productids as $productid)
{
$products = @mysql_query("SELECT name, refnum, price FROM product, deliveryprice WHERE id='$productid' AND deliveryprice.productid='$productid'");
while ($product = mysql_fetch_array($products))
{
$refnum = $product['refnum'];
$name = $product['name'];
$price = $product['price'];
echo "<p>$refnum−$name−$price</p>";
}
}
$addonids = $_SESSION['addon'];
foreach ($addonids as $addonid)
{
$addons = @mysql_query("SELECT name, refnum, price FROM addon, addonprice WHERE id='$addonid' AND addonprice.addonid='$addonid'");
while ($addon = mysql_fetch_array($addons))
{
$refnum = $addon['refnum'];
$name = $addon['name'];
$price = $addon['price'];
echo "<p>$refnum−$name−$price</p>";
}
}
?>
<p><a href="<?php echo $_SERVER['PHP_SELF']; ?>?empty=1">Remove all items from your cart</a></p>
</body>
</html> and here is the code for form that submits:
Code:
<table width="98%">
<tr>
<?php
$addon = @mysql_query("SELECT DISTINCT id, refnum, name FROM addon, addonsubmenucat WHERE id=addonid AND catid=2 LIMIT 0, 4");
while ($addons = mysql_fetch_array($addon))
{
$addonid = $addons['id'];
$addonname = $addons['name'];
$addonrefnum = $addons['refnum'];
echo "<td align='center'><label>$addonname</label><input type='checkbox' name='addon[]' value='$addonid'></td>\n";
}
?>
</tr>
<tr>
<?php
$addon = @mysql_query("SELECT DISTINCT id, refnum FROM addon, addonsubmenucat WHERE id=addonid AND catid=2 LIMIT 0, 4");
while ($addons = mysql_fetch_array($addon))
{
$addonrefnum = $addons['refnum'];
echo "<td align='center'><img src='pictures/$addonrefnum.jpg'></td>\n";
}
?>
</tr>
<input type="hidden" name="bid" value="<?php echo "$id" ;?>" />
</form>
</table> many thanks for your help