Is there a way to update a cookie after it's been set to something else?
I have a simple form which has a drop down of information. The first one is blank, unless a cookie has been stored on the users computer where it would then put the data of the cookie in the drop down. When they submit the form, it should reset the cookie to whatever was in the field. Here is the code for the first page:
(page1.php)
<?php
$employee = $HTTP_COOKIE_VARS["employee"];
print '<form method="POST" action="page2.php">
<font face="Arial">
<select size="1" name="employee">
<option>';
if ($employee == NULL){
} else {
echo $employee;
}
print '</option>
<option>One 1</option>
<option>Two 2</option>
<option>Three 3</option>
</select><input type="submit" value="Page 2" name="B1"></p>
</form>';
?>
This is the contents of the second page where the cookie is made:
(page2.php)
<?php
setcookie("employee","$employee",(time()+604800),"/","",0);
print 'Value of \$employee is ';
echo $employee;
?>
The script does what it should, stores the cookie. But if someone changes the value of the dropdown the cookie wont update. So if a user first visits chooses Two 2 then comes back and changes it to Three 3 the cookie still keeps Two 2.
Is there a way to fix this?
Thanks