3

I want to get the value of a textbox in PHP, and when I try this:

<form method=post action="update.php">
<input type="text" name="Hex" />
<input type="submit" value="OK" />  
</form>
<?php
$test = $_POST['Hex'];
echo $test;
?>      

I just get the error:

Undefined index: Hex

I've Googled to no avail; so please someone, help me!

6
  • Does your php code reside in the same file as the HTML code, or is that PHP code inside update.php? Commented Apr 28, 2012 at 19:21
  • 2
    do var_dump($_POST); in your php Commented Apr 28, 2012 at 19:22
  • @Michael It is in the update.php file. Commented Apr 28, 2012 at 19:22
  • @heximal Still getting the same error Commented Apr 28, 2012 at 19:23
  • 2
    Try putting error_reporting(E_ALL ^ E_NOTICE); before $test = ... Also, your form 'method' does not have 'brackets' ("post" instead of post). Commented Apr 28, 2012 at 19:27

4 Answers 4

6

i think the issue is with the quotation marks, @GuiceU you forgot to add the quotes to post.

Just replace your method = post with method="post"

HTML code:

<form method="post" action="update.php">
<input type="text" name="Hex" />
<input type="submit" value="OK" />  
</form>

php code:

<?php
               $test = $_POST['Hex'];
               echo $test;
?>  
Sign up to request clarification or add additional context in comments.

Comments

6

I hope this help you:

    <?php
if (isset($_POST['submit'])) {
$test = $_POST['Hex'];
echo $test;
} else { ?>
<form method="post" action="">
<input type="text" name="Hex" />
<input type="submit" value="OK" name="submit" />  
</form>
<?php } ?>

Comments

0

Use at the start of the script

<?php error_reporting(E_ALL ^ E_NOTICE); ?>

Comments

0

Your code looks fine. Still, you can try this:

Make your form like this:

<form method="post" action="update.php">

and try to use $_REQUEST instead of $_POST

3 Comments

Don't use $_REQUEST instead of $_POST if you don't have to. Security reasons.
@nauphal, then we try to figure out why it doesn't work, not expose the OP to unnecessary vulnerabilities.
i think the issue with quotation marks, @GuiceU forget to add the quotes before and after post, method="post"

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.