I’m trying to allow users to add other users on a form via a selection box. So, a user can select another user from a drop down selection, press add user, and they’re added to an array. The user can select another user, and that second user should be added to this array. Right now, each time a user is added the original user disappears. I tried using hidden inputs but I’m not having any luck.
On formprocessing.php
//this generates a list of users. The code to actually generate the users is omitted
<center><h3>Invite Friends</h3></center><br>
<form method="post">
<tr><td>Friends:</td><td><select name ="friend"><Option value="">Friends<? echo $selection; ?></Select></td>
<input type="hidden" name="hiddenFriends" value="<? echo $friends; ?>"/>
<td><input type="submit" name="submitFriend" value="Add Friend"/>
</form>
On form.php
//i'm trying to create an array of users which are added. When completed, they'll be added to the db
<?
if(isset($_POST['submitFriend'])){
if(count($_POST['hiddenFriends']) > 0){
$friend = $_POST['friend'];
array_push($friends,$_POST['friend']);
}
else{
$friends = array('');
array_push($friends,$_POST['friend']);
}
}
?><input type="hidden" name="hiddenFriends" value="<? echo $friends; ?>"/><?
print_r($friends);
?>
Dude you trying to add PHP array into html input. Its IMPOSSIBLE.
but don’t worry you can use explode and implode functions.