I have a form for editing a table in the database, when I edit a table using the forms it do nothing and give no errors. But when I edit it from phpMyAdmin it works, but if I edit it back using the php form it reverts the fields values to it's original values that I gave it in the add form. I'm using pdo class to connect to the mysql database.
Here is the php code to edit the table, it's kinda miss I know :/, note that I store the form values in arrays because I have a for loop in creating the form so it give fields for each employee and of course I change the name of the fields using a prefix:
<?php
if((isset($_GET['action'])) and ($_GET['action'] == 'edit')){
//Get employees info
$employees = PDO_FetchAll("select * from employees");
//echo "<script>alert('AA');</script>";
//Initial values
$official_days_e = array();
$official_vacations_e = array();
$attendance_days_e = array();
$present_days_e = array();
$vacations_e = array();
$vacations_record_e = array();
$table_nameE = $_POST['table_name'];
//echo "<script>alert('BB');</script>";
foreach($employees as $employee){
$official_days_e[] = $_POST[$employee['emp_id'].'_official_days_e'];
$official_vacations_e[] = $_POST[$employee['emp_id'].'_official_vacations_e'];
$attendance_days_e[] = $_POST[$employee['emp_id'].'_attendance_days_e'];
$present_days_e[] = $_POST[$employee['emp_id'].'_present_days_e'];
$vacations_e[] = $_POST[$employee['emp_id'].'_vacations_e'];
$vacations_record_e[] = $_POST[$employee['emp_id'].'_vacations_record_e'];
}
//echo "<script>alert('$official_days_e[1]');</script>";
//Edit the values in the DB
$countt = 0;
foreach($employees as $employee){
$empl_id = $employee['id'];
$official_dayss_e = $official_days_e[$countt];
$official_vacationss_e = $official_vacations_e[$countt];
$attendance_dayss_e = $attendance_days_e[$countt];
$present_dayss_e = $present_days_e[$countt];
$vacationss_e = $vacations_e[$countt];
$vacations_recordss_e = $vacations_record_e[$countt];
$countt = $countt+1;
$attendance->query("update $table_nameE set
`official_days` = $official_dayss_e,
`official_vacations` = $official_vacationss_e,
`attendance_days` = $attendance_dayss_e,
`present_days` = $present_dayss_e,
`vacations` = $vacationss_e,
`vacations_record` = $vacations_recordss_e") or die($attendance->errorInfo());
}
//echo "<script>alert('$countt');</script>";
//echo "<script>alert('Done');</script>";
echo "<script>playSound('js/sounds/sound1.ogg');</script>";
echo "<script>$.miniNoty('Done', 'success');</script>";
//echo "<script>setTimeout(function(){ window.location='attendance.php'; }, 1200);</script>";
}
The code works with no errors. Note that the add form have almost the same code, could it be a ram storing problem ?, I tried to change the variables names but didn't help.