In my application I'm trying to send an invitation for joining a group. Therefore, I want to get user_id
of the person you are inviting. At this moment, I get a value but it's always the user_id
of the last person of the results, not the person that I choose.
PRINT OUT
<div id="InviteGroupMembers">
<form action="<?php echo $_SERVER['PHP_SELF'] . "?group_id=" .$group_id; ?>" method="post">
<div >
<input type="text" name="btnSearch" placeholder="Add people to group"/>
</div>
<div>
<button type="submit" name="">Add</button>
</div>
</form>
<form action="<?php echo $_SERVER['PHP_SELF'] . "?group_id=" .$group_id; ?>" method="post">
<?php
if (is_object($searchresult))
while ($row = $searchresult -> fetch_array()) {
echo "<div><p class='searchresults'><img src='uploads/" . $row['avatar'] . " " . "' alt='' />" . $row['surname'] . " " . $row['name'] . " " . "<input type='submit' name='btnAddMember'class='addFriendToGroup' value='' /><input type='hidden' name='user_id' value='" . $row['user_id'] . "'/></p></div>"; }
?>
</form>
</div>
PHP
if (isset($_POST["btnSearch"])) {
try {
$searchinput = mysql_real_escape_string($_POST['btnSearch']);
$searchresult = $user -> Search($searchinput);
} catch(exception $e) {
$feedback = $e -> getMessage("no results");
}
}
if (isset($_POST["btnAddMember"])) {
try{
$group_receiver_id = mysql_real_escape_string($_POST['user_id']);
var_dump($group_receiver_id);
}
catch(exception $e) {
$feedback = $e -> getMessage("no results");
}
}