Hi All
I have a simple add to shortlist function using php and would like to add a success Alert message so that users know that the item was added to the shortlist.
Ive tried the following code without success.
// check if the item is in the array, if it is, do not add
if(array_key_exists($id, $_SESSION['cart_items'])){
// redirect to product list and tell the user it was added to cart
header('Location: ../sale_barn_yearlings_test2.php#'.$id.'');
echo '<script language="javascript">';
echo 'alert("item alredy in shortlist")';
echo '</script>';
}
// else, add the item to the array
else{
$_SESSION['cart_items'][$id]=$horsename;
// redirect to product list and tell the user it was added to cart
header('Location: ../sale_barn_yearlings_test2.php#'.$id.'');
echo '<script language="javascript">';
echo 'alert("item succesfully added")';
echo '</script>';
}
I have also tried it this way
// check if the item is in the array, if it is, do not add
if(array_key_exists($id, $_SESSION['cart_items'])){
// redirect to product list and tell the user it was added to cart
echo '<script language="javascript">';
echo 'alert("item alredy in shortlist")';
echo '</script>';
header('Location: ../sale_barn_yearlings_test2.php#'.$id.'');
}
// else, add the item to the array
else{
$_SESSION['cart_items'][$id]=$horsename;
// redirect to product list and tell the user it was added to cart
echo '<script language="javascript">';
echo 'alert("item succesfully added")';
echo '</script>';
header('Location: ../sale_barn_yearlings_test2.php#'.$id.'');
}
when I do it this way I can succesfully generate the elert message but then get the error message
"Warning: Cannot modify header information - headers already sent by (output started at /home/blahblahblah.php on line 24"
Can someone please correct the errors of my ways ????
Thank you