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 modified code as :
Gleitkarte.php (main page)
<?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...
Display edited data in PHP..
Moderator: General Moderators
Re: Display edited data in PHP..
First things first:
Edit your post and put the code in
Edit your post and put the code in
Code: Select all
tags. You can use the "PHP Code" button above the message box.- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Display edited data in PHP..
First off, sifting through the code was a nightmare.
The problem is here : You are telling the form to find a page called 'editPageAction.php?d=<?php echo $_GET['d'];?>' (whatever the value of $_GET['d'] might be at the given time) which it literally tries to do. Do you receive an error message when you click to acces the page?
If you change the code (on the editpage.php) to the following :
and on the 'editPageAction' page change :
to :
it should work fine.
Hope this helps
On another note
1. what value is stored in '$_GET['changes']'
2. what does the database table 'entry' look like (structure wise)
3. could you give an example of the data stored inside 'entry'? (one row will be sufficient)
The problem is here :
Code: Select all
<form action=editPageAction.php?d='<?php echo $_GET['d'];?>' method=post>If you change the code (on the editpage.php) to the following :
Code: Select all
<form action=editPageAction.php method=post>
<input type="hidden" value="<?php echo $_GET['d']; ?>" name="d" />Code: Select all
$date = $_GET['d'];Code: Select all
$date = $_POST['d'];Hope this helps
On another note
1. what value is stored in '$_GET['changes']'
2. what does the database table 'entry' look like (structure wise)
3. could you give an example of the data stored inside 'entry'? (one row will be sufficient)
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering