Hello All! I have a problem that I have not run into before. A form of mine submits itself to itself.. huh.. anyway, when it does a variable called $fname, $lname, $user_id is updated. The page itself works fine, but when I travel to other pages, the variables $SESSION['fname'], $SESSION['lname'], and $_SESSION['user_id'] are now changed to the above values? They are changed somewhere in the following code. Any light would be great!
<?php
//page security
require_once('inc_sentry.php');
$theSentry = new Sentry();
if (!$theSentry->checkLogin('','',3,'','mp_failed_access.php?back=mp_welcome.php') ){ header("Location: mp_login.php"); die(); }
// Database Connector, Validator, Common (Java PopUp Error Messages)
require_once('inc_bigthree.php');
$connector = new DbConnector();
$validator = new Validator();
?>
<html>
<head>
<title>Time Report</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<style type="text/css">
@import url(./images/cms.css);
</style>
<body>
<script language="JavaScript" src="tb_calendar.js">
</script>
<table id="main" width="300" align="center" cellpadding="0" cellspacing="0">
<tr id="title"><td align="center" colspan="6">TIME ENTRY REPORTING</td></tr>
<tr id="top-row"><td>USER</td><td>FROM</td><td>UNTIL</td></tr>
<tr id="main-row">
<form name='myform' method='POST' action='tb_report.php?a=show'>
<?php
// USER input
$results1 = $connector->query('SELECT * FROM cms_users') or die("Sql2 failed : " . mysql_error());;
echo "<td>";
echo "<select name='user_id'>";
echo "<option value=''>--select--</option>";
while($row1 = $connector->fetchArray($results1)) {
echo "<option value='".$row1["user_id"]."'>" . $row1["user"] . "</option>";
}
echo "</select>";
echo "</td>";
// FROM DATE input
$from_date = date("m/d/Y");
echo "<td>";
echo "<input type='text' size='10' value='$from_date' name='from_date'>";
echo "<a href='javascript:cal6.popup();'><img src='images/tb_calendar/cal.gif' width='16' height='16' border='0' alt='Choose From Date'></a>";
echo "</td>";
echo "<script language = 'JavaScript'>";
echo "var cal6 = new calendar2(document.forms['myform'].elements['from_date']); ";
echo "cal6.year_scroll = false;";
echo "cal6.time_comp = false;";
echo "</script>";
// UNTIL DATE input
$until_date = date("m/d/Y");
echo "<td>";
echo "<input type='text' size='10' value='$until_date' name='until_date'>";
echo "</td>";
echo "</tr>";
echo "<tr id='bottom-row'>";
echo "<td colspan='3' align='center'><input type='submit' name='submit' value='View'></td>";
echo "</tr>";
echo "</table>";
?>
<br><br>
<center><a href="mp_welcome.php">MAIN MENU</a></center>
<?php
// Validate Entry
if(isset($_GET['a']) && ($_GET['a'] == 'show')) {
$validator->validateNumber($_POST['user_id'],'User ID');
$validator->validateDate($_POST['from_date'],'From Date');
$validator->validateDate($_POST['until_date'],'Until Date');
// Display Error if one exists
if ( $validator->foundErrors() ){
javapopup('There is a problem with: '.$validator->listErrors(', '));// Show erros with comma between
}else{
//blah
$user_id = $_POST["user_id"];
$results2 = $connector->query('SELECT * FROM cms_users WHERE user_id = '.$_POST['user_id']);
$row2 = $connector->fetchArray($results2);
$fname = $row2["fname"];
$lname = $row2["lname"];
$from_date = $_POST["from_date"];
$fd_ugly = date('Y-m-d', strtotime($from_date));
$until_date = $_POST["until_date"];
$ud_ugly = date('Y-m-d', strtotime($until_date));
//
echo "<table id='main' width='800' align='center' cellpadding='0' cellspacing='0'>";
echo "<tr id='title'>";
echo "<td align='center' colspan='6'>";
echo " $fname $lname entries from: $from_date until: $until_date";
echo "</td></tr>";
//query all clients
$results3 = $connector->query('SELECT * FROM tb_clients');
//take the first and get the id
while ($row3 = $connector->fetchArray($all_clients)){
$client_id = $row3["client_id"];
$client_name = $row3["client_name"];
//query projects for that client
$results4 = $connector->query('SELECT * FROM tb_projects WHERE client_id = '.$client_id);
//take the first and get the id
while ($row4 = $connector->fetchArray($results4)){
$total = 0;
$project_id = $row4["project_id"];
$project_name = $row4["project_name"];
//query time entries to see if any exist
$results5 = $connector->query("SELECT e.*, t1.real_time AS timename1, t2.real_time AS timename2,
t3.time_value AS timename3, t4.time_value AS timename4, tb_activities.activity
FROM tb_entries e
INNER JOIN tb_available_times t1 ON e.ftime = t1.time_id
INNER JOIN tb_available_times t2 ON e.ltime = t2.time_id
INNER JOIN tb_available_times t3 ON e.ftime = t3.time_id
INNER JOIN tb_available_times t4 ON e.ltime = t4.time_id
INNER JOIN tb_activities ON e.activity_id = tb_activities.activity_id
WHERE client_id = '".$client_id."'
AND project_id = '".$project_id."'
AND user_id = '".$user_id."'
AND thedate >= '".$fd_ugly."'
AND thedate <= '".$ud_ugly."'");
if (mysql_num_rows($results5) > 0){
echo "<tr><td colspan='5'> <b>$client_name<b></td></tr>";
echo "<tr><td colapsn='5'> PROJECT: $project_name</td></tr>";
echo "<tr>";
echo "<td> <u>date</u></td>";
echo "<td><u>activity</u></td>";
echo "<td><u>description</u></td>";
echo "<td><u>begin</u> </td>";
echo "<td><u>end</u> </td>";
echo "<td><u>hours</u></td>";
echo "</tr>";
while ($row5 = $connector->fetchArray($results5)){
$uglydate = $row5['thedate'];
$nicedate = date('D (n/j)', strtotime($uglydate));
$hours = $row5['timename4'] - $row5['timename3'];
$total = $total + $hours;
echo "<tr>";
echo "<td> $nicedate</td>";
echo "<td>".$row5['activity']."</td>";
echo "<td>".$row5['description']."</td>";
echo "<td>".$row5['timename1']."</td>";
echo "<td>".$row5['timename2']."</td>";
echo "<td>$hours</td>";
echo "</tr>";
}
echo "<tr><td> </td><td> </td><td> </td><td> </td><td align='right'><b>Total:</b> </td><td><b>$total</b></td></tr>";
echo "<tr><td> </td></tr>";
}
}
}
echo "</table>";
}
}
?>
</body>
</html>