N
N
Nikita Kossman2020-02-14 15:52:13
PHP
Nikita Kossman, 2020-02-14 15:52:13

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>


connect.php
<?php
$connection = mysqli_connect('localhost', 'root', '');
$select_db = mysqli_select_db($connection, 'cs-betting');
 ?>


could you help me?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
FanatPHP, 2020-02-14
@FanatPHP

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="Регистрация прошла успешно";

R
Rsa97, 2020-02-14
@Rsa97

`name` - field named name
'name', "name" - string name It's
better to use prepared expressions with placeholders.
https://en.wikipedia.org/wiki/%D0%92%D0%BD%D0%B5%D...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question