fatal error
hi, how do i solve this error?
Fatal error: [] operator not supported for strings in /home/katrinbj.com/htdocs/shop_cart/user_cart.php on line 78
line 78 is this line:
<?php
$_SESSION['pid'][] = $HTTP_POST_VARS['pid']['pid'];
?>
no error when i run in local host , when i upload in server only got this error.
i store pid as session and when user click the pid, it will store in user cart, i do it in a way tat no matter how many times user click on the item, only one pid will be in the cart.
<?php
if (isset($HTTP_POST_VARS['pid']['pid']))
{
if (is_array($_SESSION['pid']))
{
if (!in_array($HTTP_POST_VARS['pid']['pid'], $_SESSION['pid']))
{
//echo $HTTP_POST_VARS['pid']['pid'].\"here\";
$_SESSION['pid'][] = $HTTP_POST_VARS['pid']['pid'];
}
}else
{
$_SESSION['pid'][] = $HTTP_POST_VARS['pid']['pid'];
}
}
?>
first time click is fine, but when i click the product once again, i got tat fatal error....how can i solve it?? pls advice. thanks.
Mark Hensler posted this at 19:54 — 22nd August 2002.
He has: 4,048 posts
Joined: Aug 2000
I'm not sure what's causing that error.
<?php
if (!in_array($HTTP_POST_VARS['pid']['pid'], $_SESSION['pid']))
{
//echo $HTTP_POST_VARS['pid']['pid'].\"here\";
$_SESSION['pid'][] = $HTTP_POST_VARS['pid']['pid'];
}
// that is the hard way to force a unique PID
// it's easier to just put everything into your array,
// then use array_unique()
$_SESSION['pid'][] = $HTTP_POST_VARS['pid']['pid'];
$_SESSION['pid'] = array_unique($_SESSION['pid']);
?>
Mark Hensler
If there is no answer on Google, then there is no question.
joyce posted this at 00:38 — 23rd August 2002.
They have: 164 posts
Joined: Nov 2001
tried the array_unique(), still getting the same error...
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.