There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer black screen boot computer connection crash css dell display driver drivers email error ethernet excel explorer firefox firefox 3 freeze game hard drive internet internet explorer itunes laptop linux malware monitor network networking nvidia outlook outlook 2003 outlook express partition password printer problem router slow software sound trojan usb video virus vista windows windows xp wireless
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Cannot use a scalar value as an array ?


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
robgood's Avatar
Junior Member with 9 posts.
 
Join Date: Dec 2006
08-Jul-2007, 04:27 PM #1
Cannot use a scalar value as an array ?
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&minus;$name&minus;$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&minus;$name&minus;$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
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 11:44 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.