I have a form that a user can fill out to alter an entry in a database. The entry is a particular shift (like Mondays from 0900 - 1000).
The javascript and ajax are getting the proper information from the form (checked with console.log
and .alert
), but when the page refreshes, the database entry hasn't been changed.
Here is the PHP that handles the data:
include_once 'db_connect.php';
include_once 'psl_config.php';
include_once 'functions.php';
$error_msg = "";
if (isset($_POST['uid'], $_POST['old_day'], $_POST['old_start'], $_POST['old_end'], $_POST['day'], $_POST['start_time'], $_POST['end_time'])) {
$new_start = standard_to_military($new_start);
$new_end = standard_to_military($new_end);
$uid = filter_var(INPUT_POST, 'uid', FILTER_VALIDATE_INT);
$old_day = filter_var(INPUT_POST, 'old_day', FILTER_VALIDATE_INT);
$old_start = filter_var(INPUT_POST, 'old_start', FILTER_VALIDATE_INT);
$old_end = filter_var(INPUT_POST, 'old_end', FILTER_VALIDATE_INT);
$day = filter_var(INPUT_POST, 'day', FILTER_VALIDATE_INT);
$new_start = filter_var(INPUT_POST, 'start_time', FILTER_VALIDATE_INT);
$new_end = filter_var(INPUT_POST, 'end_time', FILTER_VALIDATE_INT);
if(!filter_var(INPUT_POST, 'day', FILTER_VALIDATE_INT) || !filter_var(INPUT_POST, 'start_time', FILTER_VALIDATE_INT) || filter_var(INPUT_POST, 'end_time', FILTER_VALIDATE_INT)) {
$error_msg .= '<p class="error"> The data entered is in an incorrect format.</p>';
var_dump($error_msg);
}
else {
$stmt = "UPDATE schedule SET day = ?, start_time = ?, end_time = ?
WHERE tutor_id = ?
AND day = ?
AND start_time = ?";
$stmt->bind_param('iiiiii', $day, $new_start, $new_end, $uid, $old_day, $old_start);
$stmt->execute();
if ($stmt->errno) {
//header('../error.php?err='.$stmt->error);
$error_msg .= "FAILURE TO UPDATE";
var_dump($error_msg);
$stmt->close();
}
else {
$stmt->close();
}
}
}
The idea is that the form sends hidden input values that correspond to the shift the user is changing, and the database finds that shift and updates the entry to the data that the user put in the form.
I don't know why the database isn't recording the changes, and since I use ajax, I can't see the var_dump for the php script to see if there are problems there.