Answer the question
In order to leave comments, you need to log in
Data is not entered into the database from registration?
Hello. I am writing the registration, I seem to have done everything, but the data is not entered into the database. The second day I can not understand because of what.
register.php
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="/css/master.css">
<title>Регистрация</title>
</head>
<body>
<?php
require("connect.php");
if(isset($_POST['username']) && isset($_POST['email'])){
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
$query = "INSERT INTO `users` (`username`, `email`, `password`) VALUES (`$username`, `$email`, `$password` )";
$result = mysqli_query($connection, $query);
if($result){
$smsg="Регистрация прошла успешно";
} else {
$fsmsg="Ошибка";
}
}
?>
<form class="decor" method="post">
<div class="form-left-decoration"></div>
<div class="form-right-decoration"></div>
<div class="circle"></div>
<div class="form-inner">
<h3>Регистрация</h3>
<?php if(isset($smsg)){ ?><div class="alert alert-success" role="alert"> <?php echo $smsg; ?> </div><?php }?>
<?php if(isset($fsmsg)){ ?><div class="alert alert-danger" role="alert"> <?php echo $fsmsg; ?> </div><?php }?>
<input type="text" placeholder="Ник" required>
<input type="email" placeholder="Email" required>
<input type="password" placeholder="Пароль" required>
<input type="submit" value="Зарегистрироваться">
</div>
</form>
</body>
</html>
<?php
$connection = mysqli_connect('localhost', 'root', '');
$select_db = mysqli_select_db($connection, 'cs-betting');
?>
Answer the question
In order to leave comments, you need to log in
Throw away the tutorial that showed you this code, it never works.
Here's how to do it right:
$stmt = $connection->prepare("INSERT INTO `users` (`username`, `email`, `password`) VALUES (?,?,?)");
$stmt->bind_param("sss", $username, $email, $password);
$stmt->execute();
$smsg="Регистрация прошла успешно";
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question