我有一个简单的方法就是发送POST请求:
可以看出,在PHP服务器代码中,我有createGroup
操作,行$groupName = $_REQUEST['group_name'];
,它应接受POST请求中的group_name
参数。
但是,查看日志/或请求的结果,变量$groupName
始终为0.
我在服务器索引中有其他操作使用这个完全相同的$_REQUEST
逻辑,并且从来没有问题通过POST请求传递参数。
我怎样才能让它发挥作用?
case "createGroup":
// Getting user Id of person created, and checking if not null
if ($userId = authenticateUser($db, $username, $password, $gcmregid))
{
//echo "passed1";
$groupName = $_REQUEST['group_name'];
echo "user_sync_id is: " + $userId + ", ";
echo "groupName is: " + $groupName + ", ";
if($stmt1 = $db -> prepare("select
count(*) as num_present
from users_groups a
inner join groups b
on a.group_sync_id = b.group_sync_id
where user_sync_id = ?
and b.group_name = ?
limit 1;"))
{
$stmt1->bind_param("ss", $userId, $groupName);
$stmt1->execute();
$stmt1->bind_result($present);
//$num_affected = mysqli_affected_rows($db);
$stmt1->close();
//echo "value of present is: "+ $present;
if($present < 1)
{
if($stmt2 = $db->prepare("insert into groups(group_sync_id, group_name, created_at, group_channel_id)
SELECT
CASE
WHEN MAX(group_sync_id) is null
THEN 0
ELSE MAX(group_sync_id)
END + 1
, ?
,NOW()
,concat(SUBSTRING(MD5(NOW()),1,7) , cast(ceil(rand()*1000000) as char))
FROM groups;"))
{
$stmt2->bind_param("s", $groupName);
$stmt2->execute();
$stmt2->close();
if($stmt3 = $db-> prepare("SELECT group_sync_id, group_channel_id
from groups
where group_sync_id =
(SELECT
max(group_sync_id) as group_sync_id
FROM groups
WHERE group_name = ?);"))
{
$stmt3->bind_param("s", $groupName);
$stmt3->execute();
$stmt3->bind_result($getNewGroupId, $group_channel_id);
$stmt3->fetch();
$stmt3->close();
//echo $getNewGroupId;
if($stmt4 = $db -> prepare("insert into users_groups(user_group_sync_id, group_sync_id, user_sync_id, status, create_dt)
SELECT
CASE
WHEN max(user_group_sync_id) is null
THEN 0
ELSE max(user_group_sync_id)
END + 1
, ?
, ?
, 1
, NOW()
from users_groups;"))
{
$stmt4->bind_param("ss", $getNewGroupId, $userId);
$stmt4->execute();
$stmt4->close();
$newUsersGroup = "SELECT MAX(user_group_sync_id) as user_group_sync_id from users_groups;";
if($result5 = $db->query($newUsersGroup))
{
//echo "passed7";
$row2 = $result5->fetch_assoc();
$getNewUserGroupId = $row2['user_group_sync_id'];
$out = json_encode(array('group_sync_id' => $getNewGroupId, 'user_group_sync_id' => $getNewUserGroupId, 'group_channel_id' => $group_channel_id ));
}
else
{
$out = FAILED;
}
}
else
{
$out = FAILED;
}
}
else
{
$out = FAILED;
}
}
else
{
}
}
else
{
$out = FAILED;
}
}
else
{
$out = FAILED;
}
}
else
{
$out = FAILED;
}
break;
答案 0 :(得分:1)
+
是算术运算符而不是字符串运算符。 .
是php
echo "groupName is: " . $groupName . ", ";