Advertisement
Guest User

Untitled

a guest
Jul 14th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.08 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en" dir="ltr">
  3.   <head>
  4.     <meta charset="utf-8">
  5.     <title>s</title>
  6.  
  7.   </head>
  8.   <body>
  9.  
  10. <form action="" method="post">
  11.  
  12. Went to bed at<br>
  13. <input type="time" name="time1"><br>
  14. Woke up at:<br>
  15. <input type="time" name="time2">
  16. <input type="submit" >
  17.  
  18.  
  19.  
  20. </form>
  21.  
  22. <?php
  23.  
  24. $servername = "localhost";
  25. $username = "root";
  26. $password = "";
  27. $dbname = "db1";
  28.  
  29.  
  30. $conn = new mysqli($servername, $username, $password, $dbname);
  31.  
  32. checkConnectivity($conn);
  33.  
  34. function checkConnectivity($conn){
  35. if ($conn->connect_error) {
  36.     die("Connection failed: " . $conn->connect_error);
  37. }
  38. echo "Connected successfully";
  39. }
  40.  
  41.  
  42.  
  43.  
  44. ini_set('display_errors', 0);
  45. $current_time = strtotime($_POST['time2']);
  46. $old_time = strtotime($_POST['time1']);
  47.  
  48. $difference = $current_time -= $old_time;
  49.  
  50.  
  51. echo "You slept for: " .
  52. "<b>" .
  53. number_format((float) abs($difference / 60 / 60 ), 2, '.', '') .
  54. "</b>" .
  55. " hours.";
  56.  
  57.  
  58. $conn->query("INSERT INTO table1 (fell_asleep)
  59. VALUES ('23')");
  60.  
  61. ini_set('display_errors', 1);
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71. ?>
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement