Answer the question
In order to leave comments, you need to log in
Do not add to the database?
Hello Data is not added to the database, I will be glad if you help
index.php
<?php
require "db/db.php";
?>
<!doctype html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<title></title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-8">
<div id="login">
<h1 class="mx-auto">Регистрация</h1>
<input type="text" placeholder="Введите ваше Имя" class="form-control mt-4" v-model="name">
<input type="text" placeholder="Введите ваш Логин" class="form-control mt-4" v-model="login">
<input type="email" placeholder="Введите ваше E-Mail" class="form-control mt-4" v-model="email">
<input type="password" placeholder="Введите ваш пароль" class="form-control mt-4" v-model="password">
<button v-on:click="send_ajax" class="btn btn-success mt-4">Отправить</button>
</div>
</div>
</div>
</div>
<script>
var exampleAjax = new Vue({
el: '#login', //название ID элемента
data: {
name: '', //это типа переменная name
login:'',
email:'',
password:''
},
// определяйте методы в объекте `methods`
methods: {
send_ajax: function () {
// `this` внутри методов указывает на экземпляр Vue
fetch("request.php", {
method: 'post', //метод отправки
headers: { //заголовки (кодировка, тип и т.п)
"Content-type": "application/x-www-form-urlencoded; charset=UTF-8"
},
body: 'name='+this.name+'&login='+this.login+'&email='+this.email+'&password='+this.password //передаем ИМЯ и пароль
})
.then((response) => {
if(response.ok) {
return response.text();
}
throw new Error('Network response was not ok');
})
.then((response) => {
alert(response); //лог
})
.catch((error) => {
console.log(error);
});
}
}
})
</script>
</body>
</html>
<?php
require "../db/db.php";
$data = $_POST;
if (isset($data['send_ajax']) )
{
$errors = array( );
if (trim($data['login']) == '' )
{
$errors[] = 'Введите Логин';
}
if(strlen($data['login']) < 2 || strlen($data['login']) > 10 )
{
$errors[] = "Недопустимая Длина Логина";
}
if ( trim($data['email']) == '' )
{
$errors[] = 'Введите Email';
}
if(strlen($data['email']) < 5 || strlen($data['email']) > 30 )
{
$errors[] = "Недопустимая Длина E-Mail";
}
if ( $data['password'] == '' )
{
$errors[] = 'Введите Пароль';
}
if(strlen($data['password']) < 5 || strlen($data['password']) > 20 ){
$errors[] = "Недопустимая Длина Пароль";
}
if (empty($errors))
{
if (R::count('users', "login = ?", array($data['login'])) > 0 ){
$errors[] = 'Пользователь с таким логином есть!';
}
if (R::count('users', "email = ?", array($data['email'])) > 0 ){
$errors[] = 'Пользователь с таким Email есть!';
}
$user = R::dispense('users');
$user->name = $data['name'];
$user->login = $data['login'];
$user->email = $data['email'];
$user->password = $data['password'] = password_hash($data['password'], PASSWORD_DEFAULT);
R::store($user);
?>
<div class="alert alert-success" role="alert">
<p>Вы Успешно Зарегистрировались</p>
</div>
<?php }
else{ ?>
<div class="alert alert-danger" role="alert">
<?php echo array_shift($errors); ?>
</div>
<?php } } ?>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question