So I'm trying to return items from an array that's made out of user inputted info from cookies, and it works fine, except when you first visit the page from the previous page, nothing shows up, and you have to refresh it to actually see the array. I have no idea why it wouldn't show up the first time around? (There are some JavaScript alerts in there that work fine. It's only the array that I'm having trouble with.) Here's my code, any advice would be great, thanks:
$usergatsby = $_COOKIE['gatq'];
$usercatcher = $_COOKIE['catcherq'];
$userwaves = $_COOKIE['wavesq'];
$userstranger = $_COOKIE['strangerq'];
$userulysses = $_COOKIE['ulyssesq'];
$userpride = $_COOKIE['prideq'];
$usermockingbird = $_COOKIE['mockingbirdq'];
$userroad = $_COOKIE['roadq'];
if ($_COOKIE['fname'] == NULL or $_COOKIE['lname'] == NULL or $_COOKIE['address'] == NULL or $_COOKIE['city'] == NULL or $_COOKIE['state'] == NULL or $_COOKIE['zip'] == NULL or $_COOKIE['email'] == NULL)
{echo "<script language='javascript'>
window.alert('You left some information on the personal info page! You will be redirected.');
window.location.href='personal.php';</script>";
}
else
{
if ($_COOKIE['gatq'] == NULL &&
$_COOKIE['catcherq'] == NULL &&
$_COOKIE['wavesq'] == NULL &&
$_COOKIE['strangerq'] == NULL &&
$_COOKIE['ulyssesq'] == NULL &&
$_COOKIE['prideq'] == NULL &&
$_COOKIE['mockingbirdq'] == NULL &&
$_COOKIE['roadq'] == NULL)
{echo "<script language='javascript'>
window.alert('You don't have anything in your shopping cart! You will be redirected.');
window.location.href='inventory.php';</script>";
}
else
{$productarray = array($usergatsby=>'The Great Gatsby <img src="gatsby.jpg">',
$usercatcher=>'Catcher in the Rye <img src="catcher.jpg">',
$userwaves=>'The Waves <img src="waves.jpg">',
$userstranger=>'The Stranger <img src="stranger.jpg">',
$userulysses=>'Ulysses <img src="ulysses.jpg">',
$userpride=>'Pride and Prejudice <img src="pride.jpg">',
$usermockingbird=>'To Kill a Mockingbird <img src="mockingbird.jpg">',
$userroad=>'On the Road <img src="ontheroad.jpg">'
);
asort($productarray);
foreach ($productarray as $book=>$info)
{if ($book > 0)
{echo "Quantity: " . $book . " " . $info . "<br>";}
}
}
}
?>