PHP GCM 未定义索引
PHP GCM Undefined Index
执行我的函数时,出现错误:
[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;
}
}
不明白为什么会出现这个错误,如何缓解?
更新:
这是在用户发送消息后向 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;
}
您的 POST 数据不包含名为 syncNewData
的变量。这一行:
$pushMessageTag = isset($_POST["syncNewData"]) ? $_POST["syncNewData"] : $_POST["syncNewData"];
这似乎是在测试该变量是否存在,将参考 $_POST['syncNewData']
它是否已设置。
你可能需要
$pushMessageTag = isset($_POST["syncNewData"]) ? $_POST["syncNewData"] : '';
这将 return 存在的变量 f,如果不存在则为空字符串
执行我的函数时,出现错误:
[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;
}
}
不明白为什么会出现这个错误,如何缓解?
更新:
这是在用户发送消息后向 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;
}
您的 POST 数据不包含名为 syncNewData
的变量。这一行:
$pushMessageTag = isset($_POST["syncNewData"]) ? $_POST["syncNewData"] : $_POST["syncNewData"];
这似乎是在测试该变量是否存在,将参考 $_POST['syncNewData']
它是否已设置。
你可能需要
$pushMessageTag = isset($_POST["syncNewData"]) ? $_POST["syncNewData"] : '';
这将 return 存在的变量 f,如果不存在则为空字符串