Cookies with databases
| From: | Jason T. Davidson | Date: | Thu, 21 Oct 2004 00:54:54 +0000 |
| Subject: | Cookies with databases | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-36948@lists.php.net to get a copy of this message | ||
I am trying to set a cookie with a value from a database. Here is my script:
<? //Setting Cookies
setcookie ('CIDcookie', "$cid");
setcookie ('USERcookie', "$user");
?>
<?
//Database connection
require ("../../db_connect.php");
//Table Name
$main_tbl = "MAIN"
?>
<?
//Check the Password against the CID
$query="SELECT * FROM $main_tbl WHERE CID='$cid'";
$result=mysql_query($query) or die(mysql_error());
$check=mysql_fetch_array($result);
if ($Message == "NoAccess"){
echo("<B><CENTER><FONT COLOR=RED>You do not have access to that page!</FONT></CENTER></B>\n");
include ("staff_code/admin_links.php");
}
if ($check[PASSWORD] != $_REQUEST[password]){
header("Location:staff_login.php?Message=Invalid");
}
if (($check[PASSWORD] == $_REQUEST[password]) AND ($check[USER] == "A")) {
include ("staff_code/admin_links.php");
$user = $check[USER];
}
else{
include ("staff_code/controller_links.php");
}
?>
Then on the second page it is reading the cookies, but it will display the CIDcookie, but not the USERcookie. Here is the script on the second page:
<? //Retrieve Cookies
$cid = $_COOKIE['CIDcookie'];
$user = $_COOKIE['USERcookie'];
?>
<html>
<head>
<title>ZMP ARTCC: Staff To Do List</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<?
echo ("My CID is $cid");
echo ("$user");
?>
<body text="#000066" link="#000066" vlink="#000066" alink="#000066">
<table width="600">
<tr>
<td><div align="center"><font size="4"><strong>ZMPs Staff TO Do List</strong></font></div></td>
</tr>
</table>
<br>
<table width="600">
<tr>
<td colspan="3" bgcolor="#999999"><div align="center"><strong><font size="3">Completed Tasks</font></strong></div></td>
</tr>
<tr bgcolor="#CCCCCC">
<td width="100"><div align="center">Date Finished</div></td>
<td width="250"><div align="center">Task</div></td> <td width="250"><div align="center">Status</div></td></tr> <tr> <td><div align="center">10-13-04</div></td> <td><div align="center">DLH SOP (new)</div></td> <td><div align="center">Awaiting finish of other projects</div></td> </tr> <tr> <td><div align="center">10-18-04</div></td> <td><div align="center">ZMP Policies</div></td> <td><div align="center">"</div></td> </tr> </table> <br> <table width="600"> <tr> <td colspan="3" bgcolor="#999999"><div align="center"><strong><font size="3">
Tasks Awaiting VATUSA Approval</font></strong></div></td></tr> <tr bgcolor="#CCCCCC"> <td width="100"><div align="center">Date Sent</div></td>
<td width="250"><div align="center">Task</div></td>
<td width="250"><div align="center">Status</div></td>
</tr>
<tr>
<td><div align="center">10-09-04</div></td>
<td><div align="center">LNK SOP (new)</div></td>
<td><div align="center">Awaiting approval</div></td>
</tr>
<tr>
<td><div align="center">10-19-04</div></td>
<td><div align="center">M98 SOP</div></td>
<td><div align="center">Awaiting Approval</div></td>
</tr>
<tr>
<td><div align="center">10-19-04</div></td>
<td><div align="center">General SOP</div></td>
<td><div align="center">Awaiting Approval</div></td>
</tr>
</table>
</body>
</html>
So I am assuming that somewhere in my first page that my cookie isn't actually gettting set properly. I have tried many varitites and can't find any help sections on cookies from a database. Any help would be appreciated!
--
Jason Davidson