久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

PHP 錯誤:注意:未定義索引:

PHP error: Notice: Undefined index:(PHP 錯誤:注意:未定義索引:)
本文介紹了PHP 錯誤:注意:未定義索引:的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在用 PHP 處理購物車,但似乎在各種地方都收到此錯誤注意:未定義索引:".錯誤是指不同地方編碼的相似位.例如,我有一段代碼可以計算用戶決定訂閱的月份的套餐價格.我有以下錯誤所指的變量:

I am working on a shopping cart in PHP and I seem to be getting this error "Notice: Undefined index:" in all sorts of places. The error refers to the similar bit of coding in different places. For example I have a piece of coding that calculates a package price with the months a user decides to subscribe. I have the following variables where the errors refers to:

    $month = $_POST['month'];
    $op = $_POST['op'];

$month 變量是用戶在表單中輸入的數字,$op 變量是不同的包,其值存儲在用戶從表單上的單選按鈕中選擇的變量中.

The $month variable is the number the user inputs in a form, and the $op variable is different packages whose value are stored in a vriable that a user selects from radio buttons on the form.

我希望這在某種程度上是清楚的.

I hope that is clear in some way.

謝謝

抱歉忘了提到當用戶提交數據時它們會消失.但是當他們第一次來到頁面時,它會顯示這個錯誤.我怎樣才能擺脫它而不顯示它?

Sorry forgot to mention that they do go away when the user submits the data. But when they first come to the page it displays this error. How I can get rid of it so it doesnt display it?

--

這是代碼:

<?php
    $pack_1 = 3;
    $pack_2 = 6;
    $pack_3 = 9;
    $pack_4 = 12;
    $month = $_POST['month'];
    $op = $_POST['op'];
    $action = $_GET['action'];

    if ( $op == "Adopter" ) {
       $answer = $pack_1 * $month;
    }

    if ( $op == "Defender" ) {
      $answer = $pack_2 * $month;
    }

    if ( $op == "Protector" ) {
      $answer = $pack_3 * $month;
    }

    if ( $op == "Guardian" ) {
      $answer = $pack_4 * $month;
    }

    switch($action) {   
        case "adds":
            $_SESSION['cart'][$answer][$op];
            break;
    }
?>  

推薦答案

您正試圖訪問未設置的數組中的索引.這會引發通知.

You're attempting to access indicies within an array which are not set. This raises a notice.

很可能您現在已經注意到它,因為您的代碼已移至 php.ini 將 error_reporting 設置為包含 E_NOTICE 的服務器.通過將 error_reporting 設置為 E_ALL & 來抑制通知~E_NOTICE(不推薦),或者在嘗試訪問之前驗證索引是否存在:

Mostly likely you're noticing it now because your code has moved to a server where php.ini has error_reporting set to include E_NOTICE. Either suppress notices by setting error_reporting to E_ALL & ~E_NOTICE (not recommended), or verify that the index exists before you attempt to access it:

$month = array_key_exists('month', $_POST) ? $_POST['month'] : null;

這篇關于PHP 錯誤:注意:未定義索引:的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Cannot use #39;Object as class name as it is reserved Cake 2.2.x(不能使用 Object 作為類名,因為它是保留的 Cake 2.2.x)
Session is lost after an OAuth redirect(OAuth 重定向后會話丟失)
Pagination Sort in Cakephp 3.x(Cakephp 3.x 中的分頁排序)
CakePHP Shared core for multiple apps(CakePHP 多個應用程序的共享核心)
Login [ Auth-gt;identify() ] always false on CakePHP 3(在 CakePHP 3 上登錄 [ Auth-identify() ] 始終為 false)
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 87 bytes)(致命錯誤:允許的內存大小為 134217728 字節已用盡(嘗試分配 87 字節))
主站蜘蛛池模板: 亚洲综合久久精品 | 成人欧美一区二区三区在线观看 | 午夜精品一区 | 91欧美精品成人综合在线观看 | 国产视频一二三区 | 亚洲视频中文字幕 | 999热精品| 久久久成 | 97免费在线观看视频 | 国产成人jvid在线播放 | 综合国产第二页 | 国产精品成人国产乱一区 | 国产一区影院 | 亚洲精品一区二区三区蜜桃久 | 欧美精品一区二区三区蜜臀 | 一区二区福利视频 | 欧美另类视频 | 4h影视| 久久久久国产精品一区 | 欧美成人a∨高清免费观看 欧美日韩中 | 亚洲精品成人在线 | 伊人网在线综合 | 97国产在线观看 | 一级a性色生活片久久毛片 一级特黄a大片 | 亚洲精品一区二区三区四区高清 | 网色| 国产精品日韩欧美一区二区三区 | 日韩中文字幕 | 视频在线观看一区 | 色女人天堂| 国产三级大片 | 国产一区二区三区在线看 | 日本不卡一区二区三区 | 国产一区二区三区四区五区3d | 国产二区三区 | 国产美女在线播放 | 97超碰在线播放 | 午夜免费观看网站 | av一二三区 | 夜夜骑首页 | 日韩电影一区二区三区 |