After changing a form on my site to submit to the current page and not to a different page, the data read from the cookies is one step behind what I would expect.
The first part of the script checks if the page has been loaded using the purchae button, and if so the order fields are put in a cookie:
<?php
if(isset($Purchase_x))
{
$new=array();
foreach($_POST as $key => $value)
{
$new[$key] = stripslashes($value);
}
setcookie ('cart_cookie', base64_encode (serialize ($new)));
....
....
?>
The script then checks if the required fields were filled in. If so the user is taken a different page (this all works fine) if not, an error message is defined as $msg and the script contines to display the current page again:
<?php
display_html_header();
display_cart($msg);
display_html_footer();
function display_checkout_form($msg)
{
$cart_cookie = (unserialize (base64_decode ($_COOKIE['cart_cookie'])));
extract($cart_cookie);
.....
<input type = text name = name value = "<?= $name; ?>" maxlength = 40 size = 40>
........
?>
The cookie is used to prefil the the order fields when an error occurs. Here lies the problem, say you go to the store with no cookies, you enter your name as "A" but you miss another field so the form is displayed again.
In theory the field should be prefilled with "A" becuase of the cookies, but the field is empty. It looks the cookies are doing nothing, but no, because if you then change "A" to "B" and still leave something else out to cause an error, then when the page is displayed again showing the error, the field is filled with the "A", so its taken the cookie from one step back if you see what I mean.
I have checked through the code loads of times to find a mistake that is causing this but I can't see it!
P.S. The "....." in the code is just for this post to keep things simple.