I'm finding that my session variable isn't following through from script to script. I'm creating a library database for school and I want the administrator to be able to open user accounts and view the details. This works fine. I then set the account number as a session variable for use with various sections. Here are the steps I'm going through, I need to list it out to get it right XD
1. Log into 20023926 - runs userPanel.php
2. remove book on hold - calls removeHoldsRequests.php and uses $_SESSION set in userPanel, redirects to userPanel
3. go back to control panel - click link back to adminControl.php
4. log into 20023927 - runs userPanel.php should set new cardNumber as SESSION
5. remove book on hold - redirects to userPanel for 20023926
Here are my scripts.
userPanel.php
<html>
<head>
<link rel="stylesheet" type="text/css" href="http://localhost/Library/stylesheets/Library.css">
</head>
<body>
<div id="container">
<div id="header">
<div id="logo"><a href="http://localhost/Library/php/library.php"><img src="http://localhost/Library/images/theLibrary.png"></a></div>
<div id = "menu">
<?php
include ('File:///C:/wamp/www/Library/php/menu.php');
$thisPage = 'page three';
$_SESSION['thispage'] = $thisPage;
?>
</div>
</div>
<div id="body">
<div id="content">
<?php
if($username == "admin"){
if(isset($_GET['q'])){
$cardNumber = $_GET['q'];
if(isset($_GET['r'])){
if($_GET['r'] == "removed"){
print("<p>Hold/Request has been removed</p>");
}
if($_GET['r'] == "request"){
print("<p>Request has been added</p>");
}
if($_GET['r'] == "hold"){
print("<p>Hold has been added</p>");
}
if($_GET['r'] == "removeFine"){
print("<p>Fine has been removed</p>");
}
if($_GET['r'] == "checkedout"){
print("<p>Book is all ready checked out</p>");
}
if($_GET['r'] == "waiting"){
$queue = $_SESSION['queue'];
print("<p>$queue member(s) waiting for this book</p>");
}
if($_GET['r'] == "added"){
print("<p>Books has been checked out</p>");
}
if($_GET['r'] == "renew"){
print("<p>Books has been renewed</p>");
}
if($_GET['r'] == "notRenew"){
print("<p>Book can not be renewed</p>");
}
}
}
else{
$cardNumber=$_POST['cardNumber'];
$_SESSION['cardNumber'] = $cardNumber;
}
}
else{
$cardNumber = $_SESSION['username'];
}
$query = "SELECT * FROM cardholders WHERE cardNumber = '$cardNumber'";
$result=@mysql_query($query) or die(mysql_error());
$number=mysql_numrows($result);
if($number==0)
print("<center><p>No match</p></center>");
else if($number > 0){
print("<center><h2>User Information</h2></center>");
print("<center><table class=\"table\" border = \"2\"");
print("<tr>
<td>cardNumber</td>
<td>cardName</td>
<td>cardAddress</td>
<td>cardPhone</td>
</tr>");
$i=0;
while($i<$number){
$cardNumber = mysql_result($result, $i, "cardNumber");
$cardName = mysql_result($result,$i, "cardName");
$cardAddress = mysql_result($result, $i,"cardAddress");
$cardPhone = mysql_result($result, $i, "cardPhone");
print("<tr>
<td>$cardNumber</td>
<td>$cardName</td>
<td>$cardAddress</td>
<td>$cardPhone</td>
</tr>");
$i++;
}
print("</table></center>");
}
$query = "SELECT * FROM checkout JOIN books ON checkout.libraryID = books.libraryID and checkinDate = '0000-00-00' and checkout.cardNumber = '$cardNumber'";
$result=@mysql_query($query) or die(mysql_error());
$number=mysql_numrows($result);
$here = '<a href="http://localhost/Library/php/history.php?q='. $cardNumber . '">here</a>';
//START OF BOOKS TABLE
if($number==0)
print("<center><p>No books have been loaned out by this card</p></center>");
else if($number > 0){
print("<center><h2>Books borrowed</h2>");
print("<table class=\"table\" border = \"2\"");
print("<tr>
<td>libraryID</td>
<td>title</td>
<td>author</td>
<td>checkoutDate</td>
<td>dueDate</td>
<td>Renew</td>
</tr>");
$i=0;
while($i<$number){
$libraryID = mysql_result($result, $i, "libraryID");
$title = mysql_result($result, $i, "title");
$author = mysql_result($result,$i, "author");
$checkoutDate = mysql_result($result, $i,"checkoutDate");
$dueDate = mysql_result($result, $i, "dueDate");
$renew = '<a href="http://localhost/Library/php/renew.php?q='. $libraryID . '">Renew</a>';
print("<tr>
<td>$libraryID</td>
<td><a href=\"http://localhost/Library/php/details.php?q=". $title . "\">$title</a></td>
<td>$author</td>
<td>$checkoutDate</td>
<td>$dueDate</td>
<td>$renew</td>
</tr>");
$i++;
}
print("</table></center>");
}
print("<p>click $here to view card history</p>");
//START OF FINES TABLE
$curDate = new DateTime();
$query = "SELECT * FROM checkout WHERE dueDate < CURDATE() and cardNumber = '$cardNumber'";
$result = mysql_query($query) or die(mysql_error());
$lateBooks=mysql_numrows($result);
if($lateBooks == 0){
print("<p>There are no fines on this account</p></center>");
}
else if($lateBooks > 0){
$i=0;
while($i < $lateBooks){
$dueDate = mysql_result($result, $i, "dueDate");
$bookDue = new DateTime($dueDate);
$libraryID = mysql_result($result, $i, "libraryID");
$finePerDay = 0.15;
$paid = "SELECT status FROM fines WHERE libraryID = '$libraryID'";
$interval = $bookDue->diff($curDate);
(int)$daysLate = $interval->d;
$queryFines = "SELECT libraryID from fines WHERE libraryID = '$libraryID'";
$resultFines = mysql_query($queryFines) or die(mysql_error());
$exists = mysql_numrows($resultFines);
if($exists == 0){
$fines = "INSERT INTO fines VALUES('$libraryID','$cardNumber','$daysLate' ,'')";
$result = mysql_query($fines) or die(mysql_error());
$fine = $daysLate * $finePerDay;
}
$fine = $daysLate * $finePerDay;
$i++;
}
$query = "SELECT * FROM fines WHERE cardNumber = '$cardNumber' and status != 'paid'";
$result = mysql_query($query) or die(mysql_error());
$number=mysql_numrows($result);
if($number > 0){
print("<center><h2>Fines</h2>");
print("<table class=\"table\" border = \"2\"");
print("<tr>
<td>libraryID</td>
<td>days late</td>
<td>fine owed</td>");
if($username == "admin"){
print("<td>Remove</td>");
}
print("</tr>");
$i=0;
if($lateBooks > 0){
while($i<$number){
$libraryID = mysql_result($result, $i, "libraryID");
$daysLate = mysql_result($result, $i, "daysLate");
$remove = '<a href="http://localhost/Library/php/removeFine.php?q='. $libraryID . '">Remove</a>';
print("<tr>
<td>$libraryID</td>
<td>$daysLate</td>
<td>$fine</td>");
if($username == "admin"){
print("<td>$remove</td>");
}
print("</tr>");
$i++;
}
print("</table></center>");
}
}
}
//HOLDS REQUESTS TABLE
$query = "SELECT * FROM holdsrequests JOIN books ON books.libraryID = holdsrequests.libraryID and cardNumber = '$cardNumber'";
$result = mysql_query($query) or die(mysql_error());
$number=mysql_numrows($result);
if($number==0)
print("<center><p>No books have been requested or held by this card</p></center>");
else if($number > 0){
print("<center><h2>Holds and Requests</h2>");
print("<table class=\"table\" border = \"2\"");
print("<tr>
<td>libraryID</td>
<td>title</td>
<td>author</td>
<td>request date</td>
<td>status</td>
<td>Remove</td>
</tr>");
$i=0;
while($i<$number){
$libraryID = mysql_result($result, $i, "libraryID");
$title = mysql_result($result, $i, "title");
$author = mysql_result($result,$i, "author");
$dateSet = mysql_result($result, $i,"dateSet");
$status = mysql_result($result, $i, "status");
$remove = '<a href="http://localhost/Library/php/removeHoldsRequests.php?q='. $libraryID . '">Remove</a>';
print("<tr>
<td>$libraryID</td>
<td><a href=\"http://localhost/Library/php/details.php?q=". $title . "\">$title</a></td>
<td>$author</td>
<td>$dateSet</td>
<td>$status</td>
<td>$remove</td>
</tr>");
$i++;
}
print("</table></center>");
}
mysql_close();
if($username == "admin"){
?>
<br>
<br>
<form name="checkOut" method="post" action="http://localhost/Library/php/submitcheckOut.php">
<table class="form">
<tr>
<td>Please Enter Library Catalogue Number:</td>
</tr>
<tr>
<td><input type = "text" class="text" name = "libraryID" size = "15"></td>
</tr>
<tr>
<td><input type="submit" class="button" name ="submitbutton" value = "Checkout Book"></input></td>
</tr>
</table>
</form>
<form name="checkOut" method="post" action="http://localhost/Library/php/holdrequest.php">
<table class="form">
<tr>
<td>Please Enter Library Catalogue Number:</td>
</tr>
<tr>
<td><input type = "text" class="text" name = "libraryID" size = "15"></td>
</tr>
<tr>
<td><input type="submit" class="button" name ="submitbutton" value = "Hold or Request Book"></input></td>
</tr>
</table>
</form>
<?php
}
?>
</div>
</div>
<div id="footer"></div>
</div>
</body>
</html>
removeHoldsRequests.php
<?php
ini_set('session.cache_limiter','private');
session_start();
@mysql_connect($_SESSION['hostname'],$_SESSION['username'],$_SESSION['password']) or die(mysql_error());
@mysql_select_db($_SESSION['db']);
$cardNumber = $_SESSION['cardNumber'];
$libraryID = $_GET['q'];
$query = "DELETE FROM holdsrequests WHERE libraryID = '$libraryID' and cardNumber = '$cardNumber'";
$result = mysql_query($query) or die(mysql_error());
header("Location: http://localhost/Library/php/userPanel.php?q=" .$cardNumber. "&r=removed");
?>