2017-02-21 114 views
-2

請大家幫幫忙,是新這個......得到這個登錄錯誤當過客戶端登錄...遇到了PHP錯誤一個PHP錯誤:消息:未定義的變量:數

嚴重性:通知

消息:未定義變量:數

文件名:控制器/ Site.php

行號:42

回溯:

文件:/home/rocketmoney/public_html/application/controllers/Site.php 線:42功能:_error_handler

文件:/home/rocketmoney/public_html/index.php行:315功能: require_once

這裏是我的控制器代碼

<?php 
if ($this->form_validation->run()) { 
    if ($this->core_model->login()) { 
     $query = $this->db->get_where('users', array('number' => $number)); 
     $result = $query->row_array(); 
     $name = $result['name']; 
     $bank_details = $result['bank_details']; 
     $session_data = array('number' => $_POST['number'], 'loggedin' => TRUE, 'name' => $name); 
     $this->session->set_userdata($session_data); 
     redirect(site_url('dash')); 
    } 
}?> 
+2

其中是$ number變量?你在哪裏定義? – Sona

+2

[PHP:「注意:未定義的變量」,「注意:未定義的索引」和「注意:未定義的偏移量」可能的重複](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable- notice-undefined-index-and-notice-undef) – MrDarkLynx

+0

你知道所有上限正在考慮尖叫嗎?不善於向人們尖叫,特別是當你向他們求助時。 –

回答

0

首先,這是一個危險的代碼,因爲什麼如果$result數組是null?如果$result數組沒有namebank_details索引會怎麼樣?

順便說一句,如果你只是大概只有你得到,那麼錯誤的擔憂:以前你if條件只需添加以下行:

$number = isset($number) ? $number : '';

這條線將設置與數量變量前面的數字變量是否存在,否則會在該數字變量上放置空字符串。您提供的代碼不會提供任何提示是否將數字變量設置爲高於此代碼。所以,如果它沒有設置,那麼你在where條件檢查什麼?你正在收到錯誤。所以,這行應該解決這個編譯錯誤,但是你可能仍然有任何邏輯錯誤。