2015-10-21 12 views
1
if($_POST) 
{ 

    if(array_key_exists("item_id", $_POST)) // asking if the array exists in data.php, 
    { 


     $item_ids = $_POST["item_id"];  // temp var. to hold the data.php data 
     $price=0; 
     foreach ($items as $item) 
     { 
      foreach($item_ids as $value) 
      { 
       if($value==$item['id'])  //checking for the ids that were store in array 
       $price+=$item['price']; // adds price of the ids that are selected 
      } 

     } 
     require_once("view_confirm.php"); //shows the total of price in the view_confirm.php 
     die(); 


    //if there wasnt any selected boxes its set to true for a statement to be stated on view_items 
    } 
    $error_no_items_selected =true; 
} 

我的函數的工作,我有顯示時沒有點擊框錯誤消息的問題,我將值設置爲false上面的帖子,$error_items_selected,在我的view_items.php是HTML代碼,其中我也用:PHP錯誤信息直通控制器,以及PHP

<?php if(error_items_selected==true){echo "Click Something";} 
我每次刷新已經出現的信息頁面時

+0

'error_items_selected == true'應該是'$ error_items_selected == true' – Pete

回答

1

if(error_items_selected==true){echo "Click Something";} 

error_items_selected如果它是一個變量,應該有一個$

()如果它是一個函數調用。

如果您使用error_items_selected - PHP認爲它是一個常量。如果你沒有這樣的常量,那很明顯,error_items_selected被認爲是'error_items_selected'字符串,這絕對是

所以,正確的方法應該是:

if ($error_items_selected==true){echo "Click Something";} 

此外,在第一個代碼塊使用$error_no_items_selected。也許這只是不同的變量,但仍然 - 檢查它們。