Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.45 KB | None | 0 0
  1. <form method="POST" action="mysql.php" class="callback form-order" >
  2. <div class="row">
  3. <div class="col-md-3">
  4. <label>
  5. <p>Имя:</p>
  6. <input type="text" name="name" placeholder="Имя" required>
  7. </label>
  8. </div>
  9. <div class="col-md-3">
  10. <label>
  11. <p>Фамилия:</p>
  12. <input type="text" name="surname" placeholder="Фамилия" required>
  13. </label>
  14. </div>
  15. <div class="col-md-3">
  16. <label>
  17. <p>Отчество:</p>
  18. <input type="text" name="secondname" placeholder="Отчество" required>
  19. </label>
  20. </div>
  21. <div class="col-md-3">
  22. <label>
  23. <p>Телефон:</p>
  24. <input type="text" name="phone" placeholder="Телефон" required>
  25. </label>
  26. </div>
  27. </div>
  28. <div class="text-center">
  29. <button class="button">Отправить</button>
  30. </div>
  31.  
  32. <?php
  33.  
  34.  
  35. $method = $_SERVER['REQUEST_METHOD'];
  36.  
  37.  
  38. //Script Foreach
  39. $c = true;
  40. if ( $method === 'POST' ) {
  41.  
  42. $project_name = trim($_POST["project_name"]);
  43. $admin_email = trim($_POST["admin_email"]);
  44. $form_subject = trim($_POST["form_subject"]);
  45.  
  46. foreach ( $_POST as $key => $value ) {
  47. if ( $value != "" && $key != "project_name" && $key != "admin_email" && $key != "form_subject" ) {
  48. $message .= "
  49. " . ( ($c = !$c) ? '<tr>':'<tr style="background-color: #f8f8f8;">' ) . "
  50. <td style='padding: 10px; border: #e9e9e9 1px solid;'><b>$key</b></td>
  51. <td style='padding: 10px; border: #e9e9e9 1px solid;'>$value</td>
  52. </tr>
  53. ";
  54. }
  55. }
  56. } else if ( $method === 'GET' ) {
  57.  
  58. $project_name = trim($_GET["project_name"]);
  59. $admin_email = trim($_GET["admin_email"]);
  60. $form_subject = trim($_GET["form_subject"]);
  61.  
  62. foreach ( $_GET as $key => $value ) {
  63. if ( $value != "" && $key != "project_name" && $key != "admin_email" && $key != "form_subject" ) {
  64. $message .= "
  65. " . ( ($c = !$c) ? '<tr>':'<tr style="background-color: #f8f8f8;">' ) . "
  66. <td style='padding: 10px; border: #e9e9e9 1px solid;'><b>$key</b></td>
  67. <td style='padding: 10px; border: #e9e9e9 1px solid;'>$value</td>
  68. </tr>
  69. ";
  70. }
  71. }
  72. }
  73.  
  74. $message = "<table style='width: 100%;'>$message</table>";
  75.  
  76. function adopt($text) {
  77. return '=?UTF-8?B?'.Base64_encode($text).'?=';
  78. }
  79.  
  80. $headers = "MIME-Version: 1.0" . PHP_EOL .
  81. "Content-Type: text/html; charset=utf-8" . PHP_EOL .
  82. 'From: '.adopt($project_name).' <'.$admin_email.'>' . PHP_EOL .
  83. 'Reply-To: '.$admin_email.'' . PHP_EOL;
  84.  
  85. mail($admin_email, adopt($form_subject), $message, $headers );
  86.  
  87. <?php
  88. if (isset($_POST['name']) && isset($_POST['phone'])){
  89. //Параметры подключения в БД
  90. $host = "localhost"; //имя хоста
  91. $database = "test"; //имя базы
  92. $user = "test"; //пользователь
  93. $password = "test"; //пароль
  94. $dbtable = "Users"; //таблица
  95.  
  96.  
  97. //переменные с формы
  98. $name = $_POST['name'];
  99. $surname = $_POST['surname'];
  100. $secondname = $_POST['secondname'];
  101. $phone = $_POST['phone'];
  102. $birthdate = $_POST['birthdate'];
  103. $birhtplace = $_POST['birhtplace'];
  104. $citizenship = $_POST['citizenship'];
  105. $doc = $_POST['doc'];
  106. $docid = $_POST['docid'];
  107. $docpublish = $_POST['docpublish'];
  108. $docdate = $_POST['docdate'];
  109. $regterm = $_POST['regterm'];
  110. $comment = $_POST['comment'];
  111.  
  112.  
  113.  
  114.  
  115. //установим соединение с бд
  116. $link = mysqli_connect($host, $user, $password, $database)
  117. or die("Ошибка " . mysqli_error($link));
  118.  
  119. //внесём данные с формы в БД
  120. $result = $mysqli->query("INSERT INTO ".$dbtable." (name,phone) VALUES ('$name','$phone')");
  121.  
  122. mysqli_close($link);
  123. }
  124. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement