PHP登录页面错误,通知和警告

时间:2017-09-26 08:48:15

标签: php

我的登录页面有问题。它显示了数组到字符串转换的第31行的通知以及explode()的警告:空分隔符。另一件事是登录页面允许我在输入我的详细信息后登录。它显示我在!password验证if语句中的错误消息 这是登录页面的代码

<?php
    if ($_POST) {
      //Form validation
      if (empty($_POST['email']) || empty($_POST['password'])) {
        $errorMsg[] = 'Please enter your email or your password!';
      }
      //validating email address
      if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        $errorMsg[] = 'You must enter a valid email';
      }
      if (strlen($password)<6) {
        $errorMsg[] = 'Your password must be 6 charcters long!';
      }
      //Check if email exists in the database
      $query =$link->query("SELECT*FROM users WHERE email = '$email'");
      $user = mysqli_fetch_assoc($query);
      $user_count = mysqli_num_rows($query);
      if ($user_count < 1) {
        $errorMsg[] = 'The email you have entered does not exist on the StudBook database';
      }
      if (!password_verify($password, $user['password'] )) {
        $errorMsg[] = 'The password does not match StudBook login records. Please enter a matching one!';
      }
      //Check for errors
      if (!empty($errorMsg)) {
        echo display_errors($errorMsg);
      }else {
        //Logging the user in
        $user_id = $user['id'];
        login($user_id);
      }
    }
   ?>


this is the database code which has a warning and a notice

session_start();
require_once $_SERVER['DOCUMENT_ROOT'].'..\StudBookCom\config.php';
require_once BASEURL.'helpers/helpers.php';

$cart_id = '';
if (isset($_COOKIE[CART_COOKIE])) {
  $cart_id = sanitize($_COOKIE[CART_COOKIE]);
}

if (isset($_SESSION['SBUser'])) {
  $user_id = $_SESSION['SBUser'];
  $query = $link->query("SELECT*FROM users WHERE id = '$user_id'");//Notice
  $user_data = mysqli_fetch_assoc($query);
  $fn = explode('',$user_data['full_name']);//Error
  $user_data['first'] = $fn[0];
  $user_data['last'] = $fn[1];
}

if (isset($_SESSION['success_flash'])) {
  echo '<div class="bg-success"><p class="text-success text-center">'.$_SESSION['success_flash'].'</p></div>';
  unset($_SESSION['success_flash']);
}

if (isset($_SESSION['error_flash'])) {
  echo '<div class="bg-danger"><p class="text-danger text-center">'.$_SESSION['error_flash'].'</p></div>';
  unset($_SESSION['error_flash']);
}
?>

1 个答案:

答案 0 :(得分:-1)

您不能创建这样的数组,而是可以使用list()。

$ fn = explode(&#39;&#39;,$ user_data [&#39; full_name&#39;]); //错误

e.g。 list($ first,$ last)= explode(&#39;&#39;,$ user_data [&#39; full_name&#39;]);