The problem is that, even after I have cleared my cookies, it is still displaying the page, which my first if statement is supposed to take care of. Here is the code:
<?php
include('/Applications/MAMP/htdocs/premind/includes/vars.php');
if (!isset($_COOKIE['emailaddress'])) {
header("location:/premind/notloggedin.php");
}
mysql_connect("$host", "$username", "$password");
mysql_select_db($db_name) or die(mysql_error());
$sql4 = 'SELECT `aname`, `date`, `useremail`, `aid` FROM `data`';
$result4 = mysql_query($sql4) or die("<br />" . mysql_error());
$countrows2 = mysql_num_rows($result4);
if (!$result4) {
echo "Cannot show assignments!";
}
while ($row = mysql_fetch_array($result4)) {
if ($row['useremail'] == $_COOKIE['emailaddress']) {
echo $row['aid'] . ". " . $row['aname'] . " -- " . $row['date'] . "<br />";
echo "<br />";
}
elseif ($countrows2 == 0) {
echo "<h1>No assignments found!</h1>";
}
}
if ($countrows2 == 0) {
echo "<h1>No assignments found!</h1>";
}
?>
Try
Might also want to check !empty() just in case.
Also:
No need for the quotes here.
Is just fine
On a side note, as ComFreek mentioned, cookies are not a secure way to authorize users.