2

Need help identifying the problem with the following basic html/php code which works correctly when I input plain text in the textarea. Why does it return blank page when I enter a URL e.g. http://www.example.com?

<form action="" method="POST">
<textarea rows="10" cols="100" name="userdata">
<?=$_POST["userdata"];    ?></textarea>
<input type="submit" name="submit" value="Send" />
</form>
<?php
echo $_POST["userdata"];
?>
3
  • 3
    It works fine when I test it... Commented Jun 20, 2016 at 13:07
  • There's an error in your code $_POST["userdata"] does not exist Commented Jun 20, 2016 at 13:09
  • Is this the complete code you are using? Because this code doesn't blank out on me... Commented Jun 20, 2016 at 13:13

2 Answers 2

1

When you load page first time value of $_POST["userdata"] is not set and is empty. and when your submit then only its value changed. just because of post data.

If you again hard refresh then its value will be empty. because of not post.

Simply I must say, store data in DB and fetch and then display. To do so

  1. Post your value to another page or if in same page check by isset($_POST['userdata']) and store into db.

  2. And Fetch from db before your html and display into textarea.

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

2 Comments

This doesn't solve OP's issue of "enter a URL, it will return a blank page" - only the hard refreshing issue... (unless I've misread the OP and this)
@ʰᵈˑ I assumed its not about page its about textarea by this works correctly when i input plain text in the textarea
0

You code is working. Only first time you open the page $_POST["userdata"] does not exist yet, so try this code:

<form action="" method="POST">
<textarea rows="10" cols="100" name="userdata">
<?php 
    if (isset($_POST["userdata"])) {
        echo $_POST["userdata"];
    } 
?>
</textarea>
<input type="submit" name="submit" value="Send" />
</form>
<?php
    if (isset($_POST["userdata"])) {
        var_dump( $_POST["userdata"]);   
    } else{
        echo 'No data';
    }
?>

When you see a blank page it is an error, to see all errors, put this code on the beginning of you page:

<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
?>

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.