The problem is a edited time values not reflecting on main page i.e on Gleitkarte.php.
e.g: On edit.php page I am modifiing time value of 2010-03-30 gehen value from 09:14:00 to 19:14:00. After clicking on "check" button the page is directing to main Gleitkarte.php page but the value for 2010-03-30 gehen value is still showing as 09:14:00 instead of 19:14:00 on main page. Also the edited time value is not getting updated in database.
the code is as follows :
Gleitkarte.php
<?php
$modStr = $_GET['changes'];
$modStr = urldecode($modStr);
$modArray = explode(",", $modStr);
?>
<?php
ini_set('display_errors', '1');
$host="localhost";
$username="my_user";
$password="password";
$db_name="xyz";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
?>
<table border='2' align='center' cellspacing="8" cellpadding="8">
<tr>
<td id='a1'>Date</td>
<td id='a2'>Kommen</td>
<td id='a3'>Gehen</td>
</tr>
<tr>
<td id='a5' axis='month'>March</td>
<td></td>
</tr>
<?php
$user = 'user2';
$date = '2010-03-30'; //supplied date was wrong
$count = 1;
$lastUser = "";
$query = "SELECT * FROM entry where loguser ='$user' and date ='$date' ORDER BY date, time";
$result = mysql_query($query); //it should already stop if an error occurs
echo "<tr>";
echo "<td><a style='color: #000000; text-decoration:none' href=\"editpage.php?d=2010-03-30\"><b>2010-03-30</b></a></td>";
while($row = mysql_fetch_array($result))
{
$count++;
if($lastUser != $row['loguser']) //i added this in case you want to show all users as well
{
$lastUser = $row['loguser'];
echo '<tr><td>'.$row['loguser'].'</td><td></td><td></td></tr>';
if(!$count%2) //if last row was the first time
{
echo '</tr>';
$count++;
}
}
if($count%2) // if 2nd time 2/2=1 % returns remainder of 0
{
if($row['action'] == 'kommen' or $row['action'] == 'arbeit')
{
echo "<tr>";
echo "<td>".$row['date']."</td>";
echo '<td>'.$row['time'].'</td>';
}
else
{
//echo "<td></td>";
echo '<td>'.$row['time'].'</td>';
}
}
else//first time 1/2 = !1
{
echo "<tr>";
echo "<td>".$row['date']."</td>";
if($row['action'] == 'kommen' or $row['action'] == 'arbeit')
{
$check = 0;
//this should show all of the new values with a red border.
foreach($modArray as $time)
{
if($row['time'] == $time)
{
echo '<td style="border: 1px solid red;">'.$row['time'].'</td>';
$check = 1;
}
}
if($check == 0)
{
echo '<td>'.$row['time'].'</td>';
}
}
else
{
echo "<td></td>";
echo '<td>'.$row['time'].'</td>';
}
}
}
if(!$count%2) //if last row was the first time
{
echo '</tr>';
}
?>
</table>
editpage.php
<?php
ini_set('display_errors', '1');
$host="localhost";
$username="my_user";
$password="password";
$db_name="xyz";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
?>
<form action=editPageAction.php?d='<?php echo $_GET['d'];?>' method=post>
<table border='2' align='center' cellspacing="8" cellpadding="8">
<tr>
<td id='a1'>Date</td>
<td id='a2'>Kommen</td>
<td id='a3'>Gehen</td>
</tr>
<tr>
<td id='a5' axis='month'>March</td>
<td></td>
</tr>
<?php
$user = 'user2';
$date = $_GET['d'];
$count = 1;
$lastUser = "";
$query = "SELECT * FROM entry where loguser ='$user' and date ='$date' ORDER BY date, time";
$result = mysql_query($query); //it should already stop if an error occurs
echo "<tr>";
echo "<td><b>2010-03-30</b></td>";
while($row = mysql_fetch_array($result))
{
$count++;
if($lastUser != $row['loguser']) //i added this in case you want to show all users as well
{
$lastUser = $row['loguser'];
echo '<tr><td>'.$row['loguser'].'</td><td></td><td></td></tr>';
if(!$count%2) //if last row was the first time
{
echo '</tr>';
$count++;
}
}
if($count%2) // if 2nd time 2/2=1 % returns remainder of 0
{
if($row['action'] == 'kommen' or $row['action'] == 'arbeit')
{
echo "<tr>";
echo "<td>".$row['date']."</td>";
echo '<td>';
echo '<input type=textbox name="'.$row['time'].'"value="'.$row['time'].'">';
echo '</td>';
}
else
{
//echo "<td></td>";
echo '<td>';
echo '<input type=textbox name="'.$row['time'].'"value="'.$row['time'].'">';
echo '</td>';
}
}
else//first time 1/2 = !1
{
echo "<tr>";
echo "<td>".$row['date']."</td>";
if($row['action'] == 'kommen' or $row['action'] == 'arbeit')
{
echo '<td>';
echo '<input type=textbox name="'.$row['time'].'"value="'.$row['time'].'">';
echo '</td>';
}
else
{
echo "<td></td>";
echo '<td>';
echo '<input type=textbox name="'.$row['time'].'"value="'.$row['time'].'">';
echo '</td>';
}
}
}
if(!$count%2) //if last row was the first time
{
echo '</tr>';
}
?>
</table>
<input type=submit value=change>
</form>
editPageAction.php
<?php
ini_set('display_errors', '1');
$host="localhost";
$username="my_user";
$password="password";
$db_name="xyz";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$date = $_GET['d'];
$modStr = "";
$query = "select * from `entry` where `date`='$date'";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
if($_POST[$row['time']] == "") //check if the value is null
{
$query = "delete from entry where time ='".$row['time']."";
mysql_query($query); //delete where the value == ""
}
else if($row['time'] != $_POST[$row['time']]) //check if the value has been changed
{
/*
we are only going to record the variables that are changed, and not include the ones that are removed, because they will not show up anyway.
*/
$modStr .= $_POST[$row['time']] . ',';
$query = "update entry set time ='".$_POST[$row['time']]."' where time ='".$row['time']."'";
mysql_query($query); //change the values to the ones set
}
}
//Than after the tables have been changed, the script will redirect
$modStr = urlencode($modStr); //we encode the data for url transfer
header("location: http://localhost/Gleitkarte.php?changes=$modStr");
?>
Please help...