I
I
iiiideb2019-12-16 16:36:29
PHP
iiiideb, 2019-12-16 16:36:29

Why is the password not stored in the database?

Only the password is not entered into the mysql database, everything else is entered normally

$username = trim(filter_var($_POST['username'], FILTER_SANITIZE_STRING));
  $email = trim(filter_var($_POST['email'], FILTER_SANITIZE_EMAIL));
  $login = trim(filter_var($_POST['login'], FILTER_SANITIZE_STRING));
  $password = trim(filter_var($_POST['password'], FILTER_SANITIZE_STRING));

  $error = '';
  if(strlen($username) <= 3){
    $error = 'Введите имя';
  }else if(strlen($email) <= 3){
    $error = 'Введите емейл';
  }else if(strlen($login) <= 5){
    $error = 'Введите логин';
  }else if(strlen($password) < 8){
    $error = 'Введите пароль';
  }

  if ($error != '') {
    echo $error;
    exit;
  }

  $hash = "3h#%89*H#($h%!~fh";
  $password = md5($password);

  require "../sqlconnect.php"; #Подключение к бд через pdo
  
  $sql = 'INSERT INTO `userinfo` (`name`, `email`, `login`, `password`) VALUES(?,?,?,?)';
  $query = $pdo->prepare($sql);
  $query->execute([$username, $email, $login, $password]);

  echo 'Готово';

If you create a user through myadmin, then the password is displayed

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Savinykh, 2019-12-19
@iiiideb

require "../sqlconnect.php"; #Подключение к бд через pdo

$username = trim(filter_var($_POST['username'], FILTER_SANITIZE_STRING));
  $email = trim(filter_var($_POST['email'], FILTER_SANITIZE_EMAIL));
  $login = trim(filter_var($_POST['login'], FILTER_SANITIZE_STRING));
  $password = trim(filter_var($_POST['password'], FILTER_SANITIZE_STRING));

  $error = '';
  if(strlen($username) <= 3){
    $error = 'Введите имя';
  }else if(strlen($email) <= 3){
    $error = 'Введите емейл';
  }else if(strlen($login) <= 5){
    $error = 'Введите логин';
  }else if(strlen($password) < 8){
    $error = 'Введите пароль';
  }

  if ($error != '') {
    echo $error;
    exit;
  }

  $hash = "3h#%89*H#($h%!~fh";
  $password = md5($password);
  
  $sql = 'INSERT INTO `userinfo` (`name`, `email`, `login`, `password`) VALUES(?,?,?,?)';
  $query = $pdo->prepare($sql);
  $query->execute([$username, $email, $login, $password]);

  echo 'Готово';

It is enough to change places, because in the included file -> , it overwrites your variable with an empty line. require "../sqlconnect.php";$password = '';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question