0

I am receiving this error when trying to pass a value via hidden input in a form. I have used this multiple times before, and I can't seem to figure out why it is not passing this time in particular.

Code from the form on index:

<form method="post" action="viewchars.php">
    <input type="hidden" name="uname" value="testuser" />
</form>

Code on viewchars.php:

<?php
    $user = $_POST["uname"];
?>

The error states that uname is the undefined index.

I am not trying to get the error to just go away, as I actually need the value being passed for the viewchars.php page.

5
  • 4
    this should work. Where is your submit button? Commented Nov 29, 2012 at 23:42
  • Ah! You see no submit button because there is no submit button... You do see the problem however! Thank you user! Commented Nov 29, 2012 at 23:53
  • should work, agree. What happens if the input is made visible? Do you also have a submit button? Commented Nov 29, 2012 at 23:54
  • What happens if you add the submit button and try with that? Commented Nov 29, 2012 at 23:59
  • how you are submitting that form? If its not present then probably here is problem - anyways you should check if value exists and handle situation when it is not present (like $user = isset($_POST['uname']) ? $_POST['uname'] : null;). Commented Nov 30, 2012 at 0:27

5 Answers 5

1

add submit button in your html

<form method="post" action="viewchars.php">
    <input type="hidden" name="uname"  value="testuser" />
    <input type="submit" value="Submit"/>
</form>
Sign up to request clarification or add additional context in comments.

Comments

1

You have to make sure the form is submitted before using POST values. So it should be something like

$user = isset($_POST['uname']) ? $_POST['uname'] : '';

Comments

0

If you are sending this via JS make sure you are actually using POST. Have you tried to test on $_REQUEST, instead?

Also, try:

  • use a submit button just to test

  • make the input visible and type text to test

  • change var name

  • try a print_r($_REQUEST); on the php side to see what is received

Comments

0

just remove "/" form end of input line! like this...

<form method="post" action="viewchars.php"> <input type="hidden" name="uname" value="testuser" > </form>

Comments

-1

try the following:

$user = $_POST['uname'];

1 Comment

Single or double quotes makes no difference.

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.