0

I am in the process of creating a site that allows users to post messages. When a user clicks on a name in their contact list, that contact becomes a variable and is added as a recipient to the message.

echo "<td><a href='mypagepost.php?contact=$contact' STYLE='TEXT-DECORATION: NONE'><font color=#808080>" . $row['contact'] . "</a></font></td>";

This is the link created in the user's recipient list. So, it takes them to mypagepost.php. At mypagepost.php, I have;

<?php $messagerecipient = $_GET['contact']; ?>

And this works. Depending on the contact clicked on the contacts list on mypage.php, it will be stored as $messagerecipient. However, I would like to set it up so that if I continue to click on more recipients from mypagepost.php, new variables will be created that can also be used in the same way (so, maybe the new variables would become $messagerecipient2, $messagerecipient3, and so forth). Is there a way to do this?

Any help is appreciated, as always.

3
  • Why are you just storing them in a database? Since you already tagged it with mysql. Or you can store them in a SESSION. Commented Aug 25, 2013 at 16:51
  • 2
    Please learn about arrays: php.net/manual/en/language.types.array.php Commented Aug 25, 2013 at 16:53
  • While neither me nor you have any influence over winning the lottery, we do have a choice of choosing what to learn. Your question is typical to people, who never heard about arrays, or for some reason do not understand them. Commented Aug 25, 2013 at 17:12

1 Answer 1

1

Why not use an array in HTML?

<?php
    print_r($_GET);
?>

<form action="" method="get">
    <input type="text" name="recipient[]">
    <input type="text" name="recipient[]">
    <input type="text" name="recipient[]">
    <input type="text" name="recipient[]">
    <input type="text" name="recipient[]">
    <input type="text" name="recipient[]">
    <input type="submit">
</form>

Example URL:

recipient%5B%5D=k&recipient%5B%5D=g&recipient%5B%5D=b&recipient%5B%5D=n&recipient%5B%5D=m&recipient%5B%5D=%2C

Example output:

Array
(
    [recipient] => Array
        (
            [0] => k
            [1] => g
            [2] => b
            [3] => n
            [4] => m
            [5] => l
        )

)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.