0

I got a very simple problem and I've searched for it for hours. But I just don't fix my error... I try to get the value of my textbox (I know, there are lots of posts but no one of them could've helped me).

I got this HTML code:

<form action="" method="post">
    <input type="text" id="address" name="address" placeholder="Enter your zip code" style="width:250px;" />
    <input type="submit" id="submit" value="Submit" />
</form>

And this is PHP code #1 I tried:

<?php
    $textboxValue = $_POST['address'];
    echo $textboxValue;
?>

This doesn't work and I don't know why. After trying this, I found another code:

<?php
    if(isset($_POST['submit'])){
        $textboxValue = $_POST['address'];
        echo $textboxValue;
    }
?>

This doesn't seem to work. Like the other one.

Is there an error or why is the $textboxValue not displayed when I call it with echo?

11
  • 2
    Are you actually submitting to the correct PHP file? Commented Dec 3, 2013 at 14:41
  • 1
    It may happen if you are trying to access post variables in another file. mention your form action file and a file where you written your above mentioned code Commented Dec 3, 2013 at 14:41
  • you are not provided name for submit button sset name as submit Commented Dec 3, 2013 at 14:41
  • It should submit to itself. So I thought action="" will do this? Commented Dec 3, 2013 at 14:42
  • 1
    @Pranavc Do not do this unless you're keen on HTML injection. Commented Dec 3, 2013 at 15:03

2 Answers 2

5

Please give the form an action!

And you have to name the submit button submit:

<input type="submit" name="submit" id="submit" value="Submit" />

Otherwise isset() will return false.

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

3 Comments

I now got action="<?php echo $_SERVER['PHP_SELF']; ?>" and <input type="submit" id="submit" name="submit" value="Submit" /> It still doesn't work :/
Yes it is... That's why I think it's strange
Hm..what's your file named? $_SERVER['PHP_SELF'] should work, but please try it with the action="yourfile.php"
-1

I found the error. In my file I had a return = false; so he couldn't execute the $_POST method. But thanks for all your help :)

2 Comments

I can't see any return in your code above. That's why you always should show the whole code.
Ok..but the solution of the code above is the answer above, because the name="" was missing. So accept the answer, please so that others not search for an return = false which doesn't exist

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.