2015-04-22 100 views
-1

在我的函數的執行,出現錯誤:PHP GCM未定義指數

[23-Apr-2015 01:08:39 Europe/Berlin] PHP Notice: Undefined index: syncNewData in C:\xampp\index.php on line 972

爲線:$pushMessageTag = isset($_POST["syncNewData"]) ? $_POST["syncNewData"] : $_POST["syncNewData"];的功能:

function updateDataGCM($db) { 
    // Get all the GCM regIDs for anyone with new, "unseen" data: 
    $sqlAllRegIds = 'select distinct gcm_registration_id 
        from users 
        where id in (
        select distinct myId as usersID from group_messages WHERE `read` = 1 
        UNION 
        SELECT distinct touid as usersID from messages where `read` = 1 
        UNION 
        SELECT distinct invited_id as usersID from event_invites where `status` = 1 
        UNION 
        select distinct receiver_id as usersID from group_invites where `status` = 1 
        UNION 
        select distinct requestId as usersID from friends where `status` = 1 
        )'; 

    // Execute 
    if ($resultIds = $db->query($sqlAllRegIds)) 
    { 

     $pushMessageTag = isset($_POST["syncNewData"]) ? $_POST["syncNewData"] : $_POST["syncNewData"]; 
     $gcmRegIds = array($resultIds); 
     $message = array("syncNewData" => $pushMessageTag); 
     $pushStatus = sendPushNotificationToGCM($gcmRegIds, $message); 
     return $pushStatus; 
    } 

} 

我不明白爲什麼這個錯誤會發生,如何緩解?

UPDATE:

這是,在用戶發送消息時,將發送的同步消息發送到GCM的操作:

case "sendGroupMessage": 
     if ($userId = authenticateUser($db, $username, $password, $gcmregid)) 
     { 
      if (isset($_REQUEST['toGroupId'])) 
      { // instead of toUserName it's to a groupId 
       $toGroupName = $_REQUEST['toGroupName']; 
       $toGroupId = $_REQUEST['toGroupId']; 
       $message  = $_REQUEST['messageText']; 
       $campaign = $_REQUEST['campaign_id']; 
       $location = $_REQUEST['location_id']; 

       // Query to get the users id's who are in the group but not the user sending the message   
       $sqlGroupMembers = "SELECT DISTINCT usersId from users_groups 
        WHERE usersId != '".$userId."' AND groupId = '".$toGroupId."'"; 


       // Loop to create a copy of message for all users taht are part of that group 
       if($getGroupMembersId = $db->query($sqlGroupMembers)) 
       { 
        while($rowGroupMembers = $db -> fetchObject($getGroupMembersId)) 
        { 
         $sql22 = "INSERT INTO `group_messages` ..."     

         error_log("$sql22", 3 , "error_log"); 
         if ($db->query($sql22)) 
         { 

          $out = SUCCESSFUL; 

         }    
         else 
         { 
          $out = FAILED; 
         }     

        }    


       } 

       // Send GCM to turn on devices: 
       echo updateDataGCM($db);     

      } 
      else 
      { 
       $out = FAILED; 
      }   

     } 
     else 
     { 
      $out = FAILED; 
     } 
    break; 

原始updateDataGCM()

工作得很好:

function updateDataGCM() { 

    $gcmRegID = 'test id' 
    $pushMessage = $_POST["syncNewData"]; 
    $gcmRegIds = array($gcmRegID); 
    $message = array("syncNewData" => $pushMessage); 
    $pushStatus = sendPushNotificationToGCM($gcmRegIds, $message); 

    return $pushStatus; 
} 
+0

是表單POST方法並執行元件承受的name屬性「syncNewData」?這些都是區分大小寫的,如果你有錯別字。 –

+1

加上這個'isset($ _ POST [「syncNewData」])? $ _POST [「syncNewData」]:$ _POST [「syncNewData」];'通常有''''而不是'isset($ _ POST [「syncNewData」])? $ _POST [「syncNewData」]:'';' –

+0

@ Fred-ii-沒有任何形式,這是嚴格的在我的PHP服務器上,並且在用戶db aciton – Sauron

回答

0

Your POST數據不包含名爲syncNewData的變量。這條線:

$pushMessageTag = isset($_POST["syncNewData"]) ? $_POST["syncNewData"] : $_POST["syncNewData"]; 

,這似乎是測試該變量的存在,將參考$_POST['syncNewData']它是否被設置。

你可能需要

$pushMessageTag = isset($_POST["syncNewData"]) ? $_POST["syncNewData"] : ''; 

的f,存在將返回變量,或一個空字符串,如果它不

+0

我說過(實際上是兩次),他們說他們仍然得到相同的錯誤。 –

+0

@Fred,或者他們更新了錯誤的代碼,或者他們的代碼中的其他地方發生了相同的錯誤,他們沒有正確讀取行號。他們現在必須爲自己弄明白。 – 2015-04-22 23:39:54

+0

是的,那麼Android的東西不是我所知道的,雖然在他們的問題中沒有發佈Android代碼;我肯定知道它不是。至於它爲什麼被貼上標籤,我不知道。錯誤很可能在他們的Android代碼中,而不是他們發佈的內容。那,以及不正確的三元組。 –