2017-09-26 64 views
-1

我的登錄頁面出現問題。它顯示了31行數組到字符串轉換的通知以及explode()的警告:空分隔符。另一件事是登錄頁面允許我在輸入我的詳細信息後登錄。這表明,我放在密碼錯誤消息驗證if語句 這是登錄頁面PHP登錄頁面錯誤,通知和警告

<?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']); 
} 
?> 
+0

你能告訴我們警告和通知嗎? –

+0

可能的重複:https://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef –

+0

我把它你想要的空間,在第一次爆炸論點 – delboy1978uk

回答

-1

不能創建數組這樣的,而不是你可以使用的list()的代碼。

$ FN =爆炸(」」,$的user_data [ 'FULL_NAME']); //錯誤

例如 list($ first,$ last)= explode('',$ user_data ['full_name']);

+0

謝謝。我沒有編碼,錯誤消失了。這真的很奇怪。 – Mark