Jump to content

Warning: Illegal string offset error


scuttzz
Go to solution Solved by requinix,

Recommended Posts

Hi all

 

Im run across an error that i cant figure out a solution to.. I get this error "Warning: Illegal string offset 'quantity' when I try echo the value for quantity. This is obviously for a online cart..

<div class="cartWrapper">
<?php 
    if(isset($_POST['submit'])){
	foreach ($_POST['quantity'] as $key => $value){
		if($val==0){
		unset($_SESSION['cart'][$key]);
		}else{
		$_SESSION['cart'][$key]['quantity']=$val;
		}
		}
	}
?>
<table class="cartTable">
	<tr style="text-align:left;">
	  <th width="20%">Product Name</th>
	  <th width="10%">Quantity</th>
	  <th width="15%">Unit Price</th>
	  <th width="20%">Total</th>
	</tr>
	<?php
	    $sql = "SELECT * FROM products WHERE id IN(";
				
		foreach ($_SESSION['cart'] as $id => $value){
		$sql.=$id.",";
		}
					
		$sql=substr($sql, 0, -1). ") ORDER BY product_name ASC";
		$query=mysql_query($sql);
		$totalprice=0;
			
	while($row=mysql_fetch_array($query)){
	$subtotal=$_SESSION['cart'][$row['id']]['quantity']*$row['price'];
	$totalprice+=$subtotal;
?>
	<tr>
	<td><?php echo $row['product_name'];?></td>
	<td><?php echo $row['id']['quantity']?></td> //ERROR IN THIS LINE
	<td>R<?php echo $row['price'];?></td>
	<td>R<?php echo $_SESSION['cart'] [$row['id']]['quantity']* $row['price'];?></td>
	</tr>
<?php
}
?>

	<tr>
	<td>Cart Total : <?php echo $totalprice; ?>
        </tr>
</table>
<br/>
<button type="submit" name="submit">Update Cart</button>
</div>

Have I made an error somewhere that I haven't seen.

Thanks in advance :)

 

Link to comment
Share on other sites

Have I made an error somewhere that I haven't seen.

Yes.

 

Thanks in advance.

You're welcome. ;)

 

What is the error? You're assuming that something exists that doesn't. $row doesn't have ['id']['quantity'], it only has $row['id'].

 

What's in that ID field? And what are you trying to accomplish ... counting something?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.