W
W
wasd3602018-06-17 10:32:47
PHP
wasd360, 2018-06-17 10:32:47

How to connect a script to work in the database?

Hello. What to add so that the registration starts working with the database?

<div class="form_modal">
                <p class="password_error">Пароли не совпадают</p>
                <p class="email_error">Введите корректный email</p>
                <p class="reg_success">Регистрация завершена</p>
                <form class="form form_registration" method="POST" action="reg_user">
                    <h4 class="form_title">Регистрация</h4>
                    <div class="form_fields">
                        <div class="form_field">
                            <label>
                                <p>Имя пользователя</p>
                                <input type="text" name="username" placeholder="Введите имя пользователя" required>
                            </label>
                        </div>
                        <div class="form_field">
                            <label>
                                <p>Пароль</p>
                                <input class="password" type="password" name="confim_password" minlength="2" placeholder="Введите Ваш Пароль" required>
                            </label>
                        </div>
                        <div class="form_field">
                            <label>
                                <p>Подтверждение пароля</p>
                                <input class="cnf_password" type="password" name="confim_password" minlength="2" placeholder="Подтвердите Ваш пароль" required>
                            </label>
                        </div>
                        <div class="form_field">
                            <label>
                                <p>Адресс электронной почты</p>
                                <input class="reg_email" type="email" name="user_email" maxlength="40" placeholder="Введите email" required>
                            </label>
                        </div>
                        <div class="form_submit">
                            <button class="form_submit-button">Создать аккаунт</button>
                        </div>
                    </div>
                </form>

<?php

$method = $_SERVER['REQUEST_METHOD'];


//Script Foreach
$c = true;
if ( $method === 'POST' ) {

  $project_name = trim($_POST["project_name"]);
  $admin_email  = trim($_POST["admin_email"]);
  $form_subject = trim($_POST["form_subject"]);


  foreach ( $_POST as $key => $value ) {
    if ( $value != "" && $key != "project_name" && $key != "admin_email" && $key != "form_subject" ) {
      $message .= "
      " . ( ($c = !$c) ? '<tr>':'<tr style="background-color: #f8f8f8;">' ) . "
      <td style='padding: 10px; border: #e9e9e9 1px solid;'><b>$key</b></td>
      <td style='padding: 10px; border: #e9e9e9 1px solid;'>$value</td>
    </tr>
    ";
  }
}
} else if ( $method === 'GET' ) {

  $project_name = trim($_GET["project_name"]);
  $admin_email  = trim($_GET["admin_email"]);
  $form_subject = trim($_GET["form_subject"]);

  foreach ( $_GET as $key => $value ) {
    if ( $value != "" && $key != "project_name" && $key != "admin_email" && $key != "form_subject" ) {
      $message .= "
      " . ( ($c = !$c) ? '<tr>':'<tr style="background-color: #f8f8f8;">' ) . "
      <td style='padding: 10px; border: #e9e9e9 1px solid;'><b>$key</b></td>
      <td style='padding: 10px; border: #e9e9e9 1px solid;'>$value</td>
    </tr>
    ";
  }
}
}

$message = "<table style='width: 100%;'>$message</table>";

function adopt($text) {
  return '=?UTF-8?B?'.base64_encode($text).'?=';
}

$headers = "MIME-Version: 1.0" . PHP_EOL .
"Content-Type: text/html; charset=utf-8" . PHP_EOL .
'From: '.adopt($project_name).' <'.$admin_email.'>' . PHP_EOL .
'Reply-To: '.$admin_email.'' . PHP_EOL;

mail($admin_email, adopt($form_subject), $message, $headers );


?>

! function(e) { var t = {};

    function n(r) { if (t[r]) return t[r].exports; var o = t[r] = { i: r, l: !1, exports: {} }; return e[r].call(o.exports, o, o.exports, n), o.l = !0, o.exports } n.m = e, n.c = t, n.d = function(e, t, r) { n.o(e, t) || Object.defineProperty(e, t, { configurable: !1, enumerable: !0, get: r }) }, n.r = function(e) { Object.defineProperty(e, "__esModule", { value: !0 }) }, n.n = function(e) { var t = e && e.__esModule ? function() { return e.default } : function() { return e }; return n.d(t, "a", t), t }, n.o = function(e, t) { return Object.prototype.hasOwnProperty.call(e, t) }, n.p = "", n(n.s = 0) }([function(e, t, n) { "use strict";
    (function(e) { n(2), window.onload = function() { e(".btn-reg").click(function() { e("#modal-container").removeAttr("class").addClass("one"), e("body").addClass("modal-active") }), e(".modal-background").click(function() { e("#modal-container").addClass("out"), e("body").removeClass("modal-active") }), e(".form_registration").submit(function() { var t = e(this),
                    n = e(".form_registration .password").val(),
                    r = e(".form_registration .cnf_password").val(),
                    o = e(".form_registration .reg_email").val(); return n !== r ? (e(".form_modal .password_error").addClass("error_visible"), !1) : (e(".form_modal .password_error").removeClass("error_visible"), !1 === /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test(o) ? (e(".form_modal .email_error").addClass("error_visible"), !1) : (e(".form_modal .email_error").removeClass("error_visible"), e.ajax({ type: "POST", url: "reg.php", data: t.serialize() }).done(function() { e(".form_modal .password_error").removeClass("error_visible"), e(".form_modal .email_error").removeClass("error_visible"), e(".reg_success").addClass("success_visible"), setTimeout(function() { t.trigger("reset"), e(".reg_success").removeClass("success_visible") }, 3e3) }), !1)) }) } }).call(this, n(1)) }, function(e, t, n) {
    var r;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yan-s, 2018-06-17
@Yan-s

Do you think you can add something and everything will miraculously start working with the database?
You should have a DB in which there should be tables with a certain structure. This structure should be designed by you according to the needs of your project. The logic of working with the database and queries will be based on this structure.
In PHP, a connection to the database is made, the received data is processed, validated, filtered, the query is built and executed.
Google SQL, PHP and MYSQL, PHP PDO.
Besides. It is highly undesirable to mix PHP and markup in the code. If you add SQL here too, it will be really bad. Read about MVC.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question