<form method="post" action="" name="signup-form">
<div class="form-element">
<label>گروه</label>
<input type="group" name="group" required />
<p>1-پایه ، 
2-دوازدهمی ،
3-فارغ التحصیل ،
4-کنکوری</p>
</div>
<div class="form-element">
<label>کد داوطلبی</label>
<input type="text" name="username" pattern="[a-zA-Z0-9]+" required />
</div>
<div class="form-element">
<label>کلمه عبور داوطلب</label>
<input type="password" name="password" required />
</div>
<div class="form-element">
<label>نام</label>
<input type="text" name="name" required />
</div>
<div class="form-element">
<label>ایمیل</label>
<input type="email" name="email" required />
</div>
<button type="submit" name="register" value="register">ثبت نام</button>
</form>
<?php
    session_start();
    include('ChatConfig.php');
    if (isset($_POST['register'])) {
        $username = $_POST['username'];
        $email = $_POST['email'];
        $password = $_POST['password'];
        $group = $_POST['group'];
        $name = $_POST['name'];
        $profile = 'https://app2.drsiamakheydari.ir/chit_chat/rtl/images/contact/1.jpg';
        $tick = '0';
        $password_hash = password_hash($password, PASSWORD_BCRYPT);
        $query = $connection->prepare("SELECT * FROM users WHERE username=:username");
        $query->bindParam("username", $username, PDO::PARAM_STR);
        $query->execute();
        if ($query->rowCount() > 0) {
            echo '<p class="error">The username address is already registered!</p>';
        }
        if ($query->rowCount() == 0) {
            $query = $connection->prepare("INSERT INTO users(number,username,password,name,email,profile,tick) VALUES (:number,:username,:password_hash,:name,:email,:profile,:tick)");
                        $query->bindParam("number", $group, PDO::PARAM_STR);
            $query->bindParam("username", $username, PDO::PARAM_STR);
            $query->bindParam("password_hash", $password_hash, PDO::PARAM_STR);
                        $query->bindParam("name", $name, PDO::PARAM_STR);
            $query->bindParam("email", $email, PDO::PARAM_STR);
            $query->bindParam("profile", $profile, PDO::PARAM_STR);
            $query->bindParam("tick", $tick, PDO::PARAM_STR);
            $result = $query->execute();
            if ($result) {
                echo '<p class="success">Your registration was successful!</p>';
            } else {
                echo '<p class="error">Something went wrong!</p>';
            }
        }
    }
?>