I have a php page with the following:

echo "<form method='post'><input type='hidden' id='memberIdd' name='memberIdd' value=" . $memberId . "></form>";

Now I created another php page and want to grab the value of this hidden field and place it into another variable. How can I do this? I tried using this for my second php page:

$member = $_POST['memberIdd'];

But I just keep getting "undefined" for $member.


Recommended Answers

All 6 Replies

Hey there,

Try using $_REQUEST ... if this isn't working, then try renaming the ID and NAME in your form.

Be sure to add an action to your form so it submits to the second script:

echo '<form method="post" action="script2.php"><input type="hidden" id="memberIdd" name="memberIdd" value=' . $memberId . '></form>';

You can then access the value as $_POST.

There is also nothing to submit the form, you need a Subit button

commented: doh! +14

You don't need the ID attribute because when you use these $_GET or $_POST, they look for the name attribute. In your case, it is name='memberIdd'


You might want to try using GET for development, so you can see if anything shows up in the URL bar. If not, the problem is with the source page. If so, the problem is with the destination page.

The destination page should set $member to either $_GET[memberidd] or $_POST[memberidd] because you can't always control which method is used. Pseudocode:

if $_GET[...]
if $_POST[...]

make sense?

in the first place it like the form contains nothing important to send. if I were you I will just use session. hope you get what am saying.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.