Formulár:
Kód:
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<b>HH:mm - prvý časovač</b><br><input name="cas1okruh2" style="text-align: center" type="time" value="<?php echo file_get_contents("values/cas1okruh2.txt");?>" required><br>
<b>HH:mm - druhý časovač</b><br><input name="cas2okruh2" style="text-align: center" type="time" value="<?php echo file_get_contents("values/cas2okruh2.txt");?>" required><br>
<b>HH:mm - dĺžka zalievania</b><br><input name="dlzkaokruh2" style="text-align: center" type="time" value="<?php echo file_get_contents("values/dlzkaokruh2.txt");?>" required><br>
<input type="submit" name="zapisatokruh2" class="btn btn-success" value="Zmeniť"> </form> </center>
PHP spracovanie a súčasné sčítanie:
Kód:
if(isset($_POST['zapisatokruh2'])){
$cas1okruh2 = $_POST['cas1okruh2'];
$cas2okruh2 = $_POST['cas2okruh2'];
$dlzkaokruh2 = $_POST['dlzkaokruh2'];
file_put_contents(__DIR__ . '/values/cas1okruh2.txt', $cas1okruh2);
file_put_contents(__DIR__ . '/values/cas2okruh2.txt', $cas2okruh2);
file_put_contents(__DIR__ . '/values/dlzkaokruh2.txt', $dlzkaokruh2);
$dlzkaokruh2d = strtotime($dlzkaokruh2);
$cas1okruh2 = strtotime($cas1okruh2);
$cas2okruh2 = strtotime($cas2okruh2);
$final = $cas1okruh2 + $dlzkaokruh2d+10800;
$final2 = $cas2okruh2 + $dlzkaokruh2d+10800;
$finaltime = date("H:i", $final);
$finaltime2 = date("H:i", $final2);
file_put_contents(__DIR__ . '/values/finalokruh2cas1.txt', $finaltime);
file_put_contents(__DIR__ . '/values/finalokruh2cas2.txt', $finaltime2);
}
?>
Nesmejte sa mi z .txt súborov, zadanie bolo bez databázy
A áno, vyriešilo to aj odčítanie strtotime("00:00")... Ale prečo je tomu tak?