I have a timer let's say 60 minutes and I want to save the timer every 1 second interval. My code is working perfectly locally but when I uploaded online. It doesn't work anymore. I got "500 (Internal Server Error)" Please help me. Your help are very much appreciated. Thank you so much guys!
Database
CREATE TABLE IF NOT EXISTS `timer` (
`id` int(6) NOT NULL,
`time` int(6) NOT NULL COMMENT 'in minutes',
`remaining_time` int(6) NOT NULL COMMENT 'seconds',
`type_id_fk` int(6) NOT NULL,
`section` int(6) NOT NULL,
`user_id_fk` int(6) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
Controller
public function updatetimer() {
$this->Mpractice->updateTimer();
}
Model
function updateTimer() {
//TIMER VAR
$timer_id = $this->input->post('timer_id');
$remaining_time = $this->input->post('remainingTime');
$this->db->trans_start();
$this->db->query("UPDATE `toefl`.`timer` SET `remaining_time` = '$remaining_time' WHERE `timer`.`id` = $timer_id;");
$this->db->trans_complete();
}
View
<div class="clock"></div>
<form method="post" action="">
<input type="hidden" id="remainingTime" value="<?= $this->Mpractice->get_timer($type); ?>">
<input type="hidden" id="timer_id" name="timer_id" value="<?= $this->Mpractice->get_timer_id($type); ?>">
</form>
Script
<script>
$(document).ready(function () {
// GET REMAINING TIME
var doUpdate = function () {
$('#remainingTime').each(function () {
var count = parseInt($(this).val());
if (count !== 0) {
$(this).val(count - 1);
}
});
};
// Schedule the update to happen once every second
setInterval(doUpdate, 1000);
// UPDATE TIMER EVERY 1SECOND
setInterval(function () {
$("#remainingTime, #timer_id").autosave({
url: "<?= site_url('practice/updatetimer'); ?>",
type: "POST",
dataType: "html",
grouped: true, //send data for all fields with the autosave
success: function () {
}
});
}, 1000);
});
</script>
Solution 1: check it first , You have use ** short tag [ <?= ?>]
**in your form please check in phpinfo short tag is on or off in your live server.
Solution 2: If you get 500 internal sever error in code you have most probably Syntax problem or SQL query problem. please check it.
If you working with AJAX please check console to get all PHP ERORR in response.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.