I have a php script that takes the input and inserts it into the mysql database. As soon as the entry in the table is completed, this script calls another script using shell_exec(). Here is the first php script:
if(isset($_POST['post_arg'])){
$theme = $_POST['topic_theme'];
$des = $_POST['detail'];
$hrs_to_go = 36;
$t = time();
$conn = mysql_connect('localhost', 'root', '') or die(mysql_error());
mysql_select_db('topics');
$sql_query = "INSERT INTO `topics`.`theme`(heading, description, hrs_to_go, status, time) VALUES ('$theme', '$des', '$hrs_to_go', 'yes', '$t')";
$ret_val = mysql_query($sql_query, $conn) or die(mysql_error());
$row = mysql_fetch_assoc(mysql_query("SELECT id FROM `theme` where heading = '$theme'"));
$themeID = $row['id'];
shell_exec("php timer_script.php $themeID");
}
I want my second script to fetch the time and hrs_to_go from my table and update the field hrs_to_go accordingly. But unfortunately the second script does not work properly and the browser keeps on loading without any redirect. Here is the second script:
ignore_user_abort(true);
session_start();
set_time_limit(0);
$conn = mysql_connect('localhost', 'root', '');
mysql_select_db('topics');
$themeID = $_SERVER['argv'][1];
$fetched_row = mysql_fetch_assoc(mysql_query("SELECT time, hrs_to_go FROM `theme` WHERE id = '$themeID'"));
while(1){
$htm = time() - (int)$fetched_row['time'];
$htm = round($htm / 3600);
$h = (int)$fetched_row['hrs_to_go'] - $htm;
if($h == 0){
mysql_query("UPDATE `theme` SET status = 'no' WHERE id = '$themeID'") or die(mysql_error());
break;
} else {
mysql_query("UPDATE `theme` SET hrs_to_go = '$new' WHERE id = '$themeID'") or die(mysql_error());
}
sleep(10);
}
Although my variables are hrs_togo but I've kept the iterval time smaller to see the changes.