问题描述
在我的函数的执行,出现错误:
[23-APR-2015年1时08分39秒欧洲/柏林] PHP公告:未定义指数:syncNewData在C:\\ XAMPP \\的index.php线972
有关该行: $ pushMessageTag =使用isset($ _ POST [syncNewData])? $ _ POST [syncNewData]:$ _ POST [syncNewData];
中的功能:
函数updateDataGCM($ DB){
//获取所有的GCM regIDs与新的看不见的数据的人:
$ sqlAllRegIds ='选择不同的gcm_registration_id
从用户
其中id在(
从group_messages其中`read` = 1选择不同的身份识别码为usersID
联盟
选择不同的消息作为touid哪里usersID'read` = 1
联盟
选择event_invites不同invited_id作为usersID其中`status` = 1
联盟
选择group_invites不同receiver_id作为usersID其中`status` = 1
联盟
选择不同的requestId从朋友那里usersID`status` = 1
); // 执行
如果($ resultIds = $ DB-GT&;查询($ sqlAllRegIds))
{ $ pushMessageTag =使用isset($ _ POST [syncNewData])? $ _ POST [syncNewData]:$ _ POST [syncNewData];
$ gcmRegIds =阵列($ resultIds);
$消息=阵列(syncNewData=> $ pushMessageTag);
$ pushStatus = sendPushNotificationToGCM($ gcmRegIds,$消息);
返回$ pushStatus;
}}
我不明白为什么会发生这样的错误,如何缓解?
更新:
这是动作是,根据用户发送消息时,会发送同步消息GCM:
案sendGroupMessage:
如果($用户id =的authenticateUser($分贝,$的用户名,密码$,$ gcmregid))
{
如果(使用isset($ _ REQUEST ['toGroupId']))
{//代替toUserName它是一个的groupId
$ toGroupName = $ _REQUEST ['toGroupName'];
$ toGroupId = $ _REQUEST ['toGroupId'];
$消息= $ _REQUEST ['MessageText中'];
$竞选= $ _REQUEST ['CAMPAIGN_ID'];
$位置= $ _REQUEST ['LOCATION_ID']; //查询来获取用户ID的谁是组而不是用户发送消息
$ sqlGroupMembers =选择users_groups DISTINCT usersId
WHERE usersId =$用户ID。'AND的groupId =$ toGroupId。'!;
//循环创建邮件的副本taht属于该组的所有用户都
如果($ getGroupMembersId = $ DB-GT&;查询($ sqlGroupMembers))
{
而($ rowGroupMembers = $ DB - > fetchObject($ getGroupMembersId))
{
$ sql22 =INSERT INTO`group_messages` ...... error_log中($ sql22,3,error_log中);
如果($ DB-GT&;查询($ sql22))
{ $出=成功; }
其他
{
$ OUT =失败;
} }
} //发送GCM开启装置:
回声updateDataGCM($分贝); }
其他
{
$ OUT =失败;
} }
其他
{
$ OUT =失败;
}
打破;
原来updateDataGCM()
工作得很好:
函数updateDataGCM(){ $ gcmRegID ='测试ID
$ pushMessage = $ _ POST [syncNewData];
$ gcmRegIds =阵列($ gcmRegID);
$消息=阵列(syncNewData=> $ pushMessage);
$ pushStatus = sendPushNotificationToGCM($ gcmRegIds,$消息); 返回$ pushStatus;
}
您POST数据不包括一个名为变量 syncNewData code>。该行:
$ pushMessageTag =使用isset($ _ POST [syncNewData])? $ _ POST [syncNewData]:$ _ POST [syncNewData];
这似乎是测试该变量的存在,将参照 $ _ POST ['syncNewData']
它是否被设置。
您可能需要
$ pushMessageTag =使用isset($ _ POST [syncNewData])? $ _ POST [syncNewData]:'';
F IT存在,或将返回变量一个空字符串如果没有
On execution of my function, the error appears:
[23-Apr-2015 01:08:39 Europe/Berlin] PHP Notice: Undefined index: syncNewData in C:\xampp\index.php on line 972
for the line: $pushMessageTag = isset($_POST["syncNewData"]) ? $_POST["syncNewData"] : $_POST["syncNewData"];
in the function:
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;
}
}
I do not understand why this error would occur, how to alleviate?
UPDATE:
This is the action that, upon a user sending a message, will send sync messages to 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;
The original updateDataGCM()
worked fine:
function updateDataGCM() {
$gcmRegID = 'test id'
$pushMessage = $_POST["syncNewData"];
$gcmRegIds = array($gcmRegID);
$message = array("syncNewData" => $pushMessage);
$pushStatus = sendPushNotificationToGCM($gcmRegIds, $message);
return $pushStatus;
}
Your POST data doesn't include a variable called syncNewData
. This line:
$pushMessageTag = isset($_POST["syncNewData"]) ? $_POST["syncNewData"] : $_POST["syncNewData"];
which seems to be testing for the existence of that variable, will refer to $_POST['syncNewData']
whether or not it is set.
You probably need
$pushMessageTag = isset($_POST["syncNewData"]) ? $_POST["syncNewData"] : '';
which will return the variable f it exists, or an empty string if it doesn't
这篇关于PHP GCM未定义指数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!