Advertisement
Guest User

Untitled

a guest
Aug 27th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.  
  4. <head>
  5. <meta charset="utf-8">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7. <title>form practice</title>
  8.  
  9. </head>
  10.  
  11. <body>
  12.  
  13. <div class="form2" id="form2" name="form2">
  14.  
  15. <form action="php/form2.php" method="post" id="Personalinfo">
  16.  
  17. <label for="fname">Name:</label>
  18. <input type="text" id="fname" name="firstname" placeholder="Client
  19. Name..">
  20.  
  21. <label for="lname">Lastname:</label>
  22. <input type="text" id="lname" name="lastname" placeholder="Client
  23. Lastname..">
  24.  
  25. <label for="dob">Birthday:</label>
  26. <input type="text" id="dob" name="dob" placeholder="yyyy/mm/dd..">
  27.  
  28. <label for="age">Age:</label>
  29. <input type="text" id="age" name="age" placeholder="Client Age..">
  30.  
  31. <input type="submit" name="submitForm2" value="Submit">
  32.  
  33. </form>
  34. </div>
  35.  
  36. </body>
  37.  
  38. </html>
  39.  
  40. <?php
  41. $servername = "localhost";
  42. $username = "root";
  43. $password = "";
  44. $dbname = "testdb";
  45.  
  46. // Create connection
  47.  
  48. $conn = new mysqli($servername, $username, $password, $dbname);
  49.  
  50. // Check connection
  51.  
  52. if ($conn->connect_error)
  53. {
  54. die("Connection failed: " . $conn->connect_error);
  55. }
  56.  
  57. if (isset($_POST['submitForm2']))
  58. {
  59. $firstname = $_POST['firstname'];
  60. $lastname = $_POST['lastname'];
  61. $dob = $_POST['dob'];
  62. $age = $_POST['age'];
  63. $sql = "INSERT INTO info (firstname, lastname, dob, age)
  64. VALUES ('{$firstname}', '{$lastname}', '{$dob}', '{$age}')";
  65. if ($conn->query($sql) === TRUE)
  66. {
  67. echo "New record created successfully";
  68. }
  69. else
  70. {
  71. echo "Error: " . $sql . "<br />" . $conn->error;
  72. }
  73. }
  74. else
  75. {
  76. echo "Are you sure you enter a firstname and the name of your html submit
  77. is submitForm";
  78. }
  79.  
  80. $conn->close();
  81. ?>
  82.  
  83. SELECT name, birth, CURDATE(),
  84. TIMESTAMPDIFF(YEAR,birth,CURDATE()) AS age
  85. FROM pet;
  86.  
  87. $now = new DateTime();
  88.  
  89. // Note your SQL field should be a `DATE` column
  90. // and formatted YYYY-MM-DD
  91. // assumed in this example $sqlData['dob'] = "2015-01-10";
  92.  
  93. $birthday = new DateTime($sqlData['dob']);
  94. $age = $now->diff($birthday);
  95. //
  96. print "person is ".$age['y']." years old.";
  97.  
  98. DateInterval Object
  99. (
  100. [y] => 2
  101. [m] => 6
  102. [d] => 23
  103. [h] => 5
  104. [i] => 34
  105. [s] => 11
  106. [days] => 935
  107. )
  108.  
  109. <head>
  110. <meta charset="utf-8">
  111. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  112. <title>form practice</title>
  113.  
  114. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  115. <script>
  116. $(document).ready(function(){
  117.  
  118. $("#dob").change(function(){
  119. var value = $("#dob").val();
  120. var dob = new Date(value);
  121. var today = new Date();
  122. var age = Math.floor((today-dob) / (365.25 * 24 * 60 * 60 * 1000));
  123. if(isNaN(age)) {
  124.  
  125. // will set 0 when value will be NaN
  126. age=0;
  127.  
  128. }
  129. else{
  130. age=age;
  131. }
  132. $('#age').val(age);
  133.  
  134. });
  135.  
  136. });
  137. </script>
  138. </head>
  139.  
  140. <body>
  141.  
  142. <div class="form2" id="form2" name="form2">
  143.  
  144. <form action="php/form2.php" method="post" id="Personalinfo">
  145.  
  146. <label for="fname">Name:</label>
  147. <input type="text" id="fname" name="firstname" placeholder="Client
  148. Name..">
  149.  
  150. <label for="lname">Lastname:</label>
  151. <input type="text" id="lname" name="lastname" placeholder="Client
  152. Lastname..">
  153.  
  154. <label for="dob">Birthday:</label>
  155. <input type="text" id="dob" name="dob" placeholder="yyyy/mm/dd..">
  156.  
  157. <label for="age">Age:</label>
  158. <input type="text" id="age" name="age" placeholder="Client Age..">
  159.  
  160. <input type="submit" name="submitForm2" value="Submit">
  161.  
  162.  
  163. </form>
  164. </div>
  165.  
  166. </body>
  167. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement