T
T
Timur-web2020-03-07 18:12:05
css
Timur-web, 2020-03-07 18:12:05

How to connect a database to commands (conversations) in php?

Help connect commands (conversations) to the database so that when you create commands it is saved in the database, preferably with ready-made code

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Команды</title>
    <link rel="stylesheet" href="../public/css/styleTeams.css">
    <link rel="stylesheet" href="../public/css/styleMainPage.css">
    <link rel="stylesheet" href="../public/css/stylePreloayder.css">   
    <link href="https://fonts.googleapis.com/css?family=Montserrat&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Poppins&display=swap" rel="stylesheet"> 

    <div class="loader">
        <div class="container-loader">
            <div class="element1"></div>
            <div class="element2"></div>
        </div>
    </div>
    <header id="header">
        <div class="container-header">
            <div class="text-header">
                <div style="padding: 0 0 45px 0;">
                    <a href="index.html">
                        <img style="position: absolute;" src="../public/img/logo.png" style="margin-bottom: 20px;" alt="Logo">
                    </a>
                </div>
                <ul>
                    <li><a href="index.html">Главная</a></li>
                    <li><a href="teams.html">Команды</a></li>
                    <li><a href="profile.html">Профиль</a></li>
                    <li><a href="index.php">Зарегистрироваться</a></li>
                    <li><a href="about.html">О нас</a></li>
                </ul>
            </div>
        </div>
    </header>
    <section class="teams">
        <div class="container-teams">
            <div class="text-teams">
                <div class="create-teams">
                    <div class="container-create-teams">
                        <div class="text-create-teams">
                            <input type="button" class="btn-create-teams" value="Создать команду"><br/>
                            <form action="" class="create-form">
                                <div class="exit-create-form">
                                    <div class="container-exit-create-form">
                                        <img src="../public/img/exit.png" class="exit-create-form" alt="exit">
                                    </div>
                                </div>
                                <input type="text" class="name-team-create" placeholder="Название команды"><br/>
                                <div class="block-error-team-create">
                                    <span class="error-team-create error">Введите значение!</span>
                                </div>
                                <input type="button" class="btn-create-form" value="Создать команду"><br/>
                            </form>
                            <div class="display-create-team">
                                <div class="container-display-create-team">
                                    <div class="text-display-create-team">
                                        <div class="heading-display-create-team">
                                            <div class="container-heading-create-team">
                                                <div class="text-heading-create-team">
                                                    <h1 class="heading-name-team"></h1>
                                                    <div class="exit-display-create-team">
                                                        <div class="container-exit-create-team">
                                                            <img src="../public/img/exit.png" alt="exit" class="exit-display-create-team">
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="message-create-team">
                                            <div class="container-message-create-team">
                                                <div class="text-message-create-team"></div>
                                            </div>
                                        </div>
                                        <form action="" class="text-message-creat-team">
                                            <textarea class="message-text" maxlength="100"></textarea><br/>
                                            <input type="button" class="btn-send-message" value="Отправить">
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="search-teams">
                    <div class="container-search-teams">
                        <div class="text-search-teams">
                            <input type="button" class="btn-search-teams" value="Искать команду"><br/>
                            <form action="" class="search-form">
                                <div class="exit-search-form">
                                    <div class="container-exit-search-form">
                                        <img src="../public/img/exit.png" class="exit-search-form" alt="exit">
                                    </div>
                                </div>
                                <input type="text" class="name-team-search" name="name_teams" id="name_teams" required placeholder="Название команды"><br/>
                                <div class="block-error-team-search">
                                    <span class="error-team-search error">Введите значение!</span>
                                </div>
                                <input type="button" class="btn-search-form" value="Искать команду"><br/>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
    <footer class="footer">
        <div class="container-footer">
            <div class="text-footer">
                <header class="header-footer">
                    <div class="container-header-footer">
                        <div class="text-header-footer">
                            <ul>
                                <li>
                                    <a href="index.html">Главная</a>
                                </li>
                                <li>
                                    <a href="teams.html">Команды</a>
                                </li>
                                <li>
                                    <a href="profile.html">Профиль</a>
                                </li>
                                <li>
                                    <a href="about.html">О нас</a>
                                </li>
                            </ul>
                        </div>
                    </div>
                </header>
                <div class="author">
                    <div class="container-author">
                        <div class="text-author">
                            <span>2019-2020 &copy;</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </footer>
    <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
    <script src="../public/js/scriptTeams.js"></script>
    <script src="../public/js/scriptPreolayder.js"></script>
</body>

</html>


<?php
// Получение данных из формы
$surname = filter_var(trim($_POST['surname']), FILTER_SANITIZE_STRING);
$name = filter_var(trim($_POST['name']), FILTER_SANITIZE_STRING);
$pass = filter_var(trim($_POST['pass']), FILTER_SANITIZE_STRING);

if(isset($_POST['password_confirm'])){ // Получаем данные из формы
    $Repass = $_POST['password_confirm'];
} else {
    $Repass = "";
}

if(mb_strlen($name) < 5 || mb_strlen($name) > 15) {
    echo "Недопустимая длина имени (от 6 до 15 символов)";
    exit();
} else if (mb_strlen($surname) < 5 || mb_strlen($surname) > 15) {
    echo "Недопустимая длина фамилии (от 6 до 15 символов)";
    exit();
} else if (mb_strlen($pass) < 5 || mb_strlen($pass) > 20) {
    echo "Недопустимая длина пароля (от 6 до 20 символов)";
    exit();
}

if($Repass == $pass){
    $pass = md5($password); //берётся переменная $pass

// Подключение к базе данных
    require "../blocks/connect.php";
    $mysql->query("INSERT INTO `users` (`name`, `surname`, `pass`) VALUES('$name', '$surname', '$pass')");

    $mysql->close();

    header('Location: /');
    
} else {
    echo 'Ошибка подтверждения пароля'; // Если пароли не совпадают, то выводим сообщение об ошибке. (Таким же способом можно выводить в конкретное поле, прописав в основном файле php)
    //include "../register.php"; // Если пароли не совпадают, то возвращаем на страницу ввода. Тут своё название и путь к файлу укажите.
}
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dima Polos, 2019-07-26
@olya_097

In the codepen, you also need to connect owl through the js settings, and not through a link in the markup. I connected and it worked.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question