Forum Moderators: coopster

Message Too Old, No Replies

Appending to a cookie.

         

eatspinach

11:05 am on Jul 3, 2009 (gmt 0)

10+ Year Member



Hi

I have a form with 12 questions and 12 buttons, when the user hits the button i want the question id of the question to be appended onto a cookie, so when the user is done the cookie will look like this, 897, 786, 678, 789.

basically i want to know how to append onto a cookie, i only know how to set a cookie.

this is what i have so far,

if (isset($_POST['addThis']))
{
$questionList = $_POST["addThis"];
echo $questionList;
setcookie("questionList", $questionList);
echo $_COOKIE["questionList"];
}

and the form is like this,

<table border="0" cellspacing="10" >
<tr><td>three</td><td><form action='quesLibrary.php' method='post'><input name='addThis' type='hidden' value='825'><input name='add1' alt='add this question' value='Add Question' type='submit'></form></td></tr><tr><td>four</td><td><form action='quesLibrary.php' method='post'><input name='addThis' type='hidden' value='826'><input name='add1' alt='add this question' value='Add Question' type='submit'></form></td></tr><tr><td>One</td><td><form action='quesLibrary.php' method='post'><input name='addThis' type='hidden' value='827'><input name='add1' alt='add this question' value='Add Question' type='submit'></form></td></tr>
</table>

any help would be appreciated,
thanks

barns101

12:05 pm on Jul 3, 2009 (gmt 0)

10+ Year Member



You should be able to append to a cookie like so:

$questionList = $_COOKIE['questionList'].', '.$_POST['addThis'];
setcookie("questionList", $questionList);

eatspinach

1:13 pm on Jul 3, 2009 (gmt 0)

10+ Year Member



That works perfectly, thanks very much!