Reputation: 6647
I have the simple aspect of sending the POST request as:
As can be seen, in the PHP server code I have the createGroup
action with, the line $groupName = $_REQUEST['group_name'];
, that should accept the group_name
parameter in the POST request.
However, looking at the log/or the result of the request, the variable $groupName
is always 0.
I have other actions in the server index that use this exact same $_REQUEST
logic and never have issues passing parameters through a POST request.
How can I get this to work?
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;
Upvotes: 1
Views: 42
Reputation: 97672
+
is an arithmetic operator not a string operator. .
is the concatenation operator for php
echo "groupName is: " . $groupName . ", ";
Upvotes: 1