Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.36 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="text-center">
  16. <button class="button">Отправить</button>
  17. </div>
  18.  
  19. <?php
  20.  
  21.  
  22. $method = $_SERVER['REQUEST_METHOD'];
  23.  
  24.  
  25. //Script Foreach
  26. $c = true;
  27. if ( $method === 'POST' ) {
  28.  
  29. $project_name = trim($_POST["project_name"]);
  30. $admin_email = trim($_POST["admin_email"]);
  31. $form_subject = trim($_POST["form_subject"]);
  32.  
  33. foreach ( $_POST as $key => $value ) {
  34. if ( $value != "" && $key != "project_name" && $key != "admin_email" && $key != "form_subject" ) {
  35. $message .= "
  36. " . ( ($c = !$c) ? '<tr>':'<tr style="background-color: #f8f8f8;">' ) . "
  37. <td style='padding: 10px; border: #e9e9e9 1px solid;'><b>$key</b></td>
  38. <td style='padding: 10px; border: #e9e9e9 1px solid;'>$value</td>
  39. </tr>
  40. ";
  41. }
  42. }
  43. } else if ( $method === 'GET' ) {
  44.  
  45. $project_name = trim($_GET["project_name"]);
  46. $admin_email = trim($_GET["admin_email"]);
  47. $form_subject = trim($_GET["form_subject"]);
  48.  
  49. foreach ( $_GET as $key => $value ) {
  50. if ( $value != "" && $key != "project_name" && $key != "admin_email" && $key != "form_subject" ) {
  51. $message .= "
  52. " . ( ($c = !$c) ? '<tr>':'<tr style="background-color: #f8f8f8;">' ) . "
  53. <td style='padding: 10px; border: #e9e9e9 1px solid;'><b>$key</b></td>
  54. <td style='padding: 10px; border: #e9e9e9 1px solid;'>$value</td>
  55. </tr>
  56. ";
  57. }
  58. }
  59. }
  60.  
  61. $message = "<table style='width: 100%;'>$message</table>";
  62.  
  63. function adopt($text) {
  64. return '=?UTF-8?B?'.Base64_encode($text).'?=';
  65. }
  66.  
  67. $headers = "MIME-Version: 1.0" . PHP_EOL .
  68. "Content-Type: text/html; charset=utf-8" . PHP_EOL .
  69. 'From: '.adopt($project_name).' <'.$admin_email.'>' . PHP_EOL .
  70. 'Reply-To: '.$admin_email.'' . PHP_EOL;
  71.  
  72.  
  73. mail($admin_email, ado
  74.  
  75. pt($form_subject), $message, $headers );
  76. ?>
  77.  
  78. <?php
  79.  
  80.  
  81. //Параметры подключения в БД
  82. $host = "11"; //имя хоста
  83. $database = "11"; //имя базы
  84. $user = "11"; //пользователь
  85. $password = "11"; //пароль
  86. $dbtable = "Users"; //таблица
  87.  
  88. if (isset($_POST['name'])){
  89. //переменные с формы
  90. $name = strip_tags(trim($_POST['name']));
  91. $surname = strip_tags(trim($_POST['surname'];
  92. $secondname = strip_tags(trim($_POST['secondname'];
  93. $phone = strip_tags(trim($_POST['phone'];
  94. $birthdate = strip_tags(trim($_POST['birthdate'];
  95. $birhtplace = strip_tags(trim($_POST['birhtplace'];
  96. $citizenship = strip_tags(trim($_POST['citizenship'];
  97. $doc = strip_tags(trim($_POST['doc'];
  98. $docid = strip_tags(trim($_POST['docid'];
  99. $docpublish = strip_tags(trim($_POST['docpublish'];
  100. $docdate = strip_tags(trim($_POST['docdate'];
  101. $regterm = strip_tags(trim($_POST['regterm'];
  102. $comment = strip_tags(trim($_POST['comment'];
  103. $date = date("Y-m-d");
  104. $time = date("H:i:s")
  105.  
  106. //установим соединение с бд
  107. $link = mysqli_connect($host, $user, $password, $database)
  108. or die("Ошибка " . mysqli_error($link));
  109.  
  110. $sql = "INSERT INTO ".$dbtable." (order_date, order_time, name, surname, second_name, phone, birth_date, birht_place, citizenship, doc, doc_id, doc_publish, doc_date, term) VALUES ('$date', '$time', '$name', '$surname', '$secondname', '$phone', '$birthdate', '$birhtplace', '$citizenship', '$doc', '$docid', '$docpublish', '$docdate', '$regterm', '$comment')"
  111.  
  112. //внесём данные с формы в БД
  113. $res = mysqli_query($sql) or trigger_error(mysqli_error()." in ". $sql);
  114.  
  115. mysqli_close($link);
  116. }
  117. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement