2

I am new to php, just trying to create a simple form but it's not working. here is my code

<?php

if (isset($_POST['user_input'])&&!empty($_POST['user_input'])){

echo "THIS WORKS!!!";
}
?>
<hr>
<form action="new.php" method="POST">
    <textarea name="user_input" rows="6" cols="30"> </textarea>
    <br>
    <br>
    <input type="submit" value="Submit">

 </form>

here is the error that appears on browser

Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream instead. in Unknown on line 0

Warning: Cannot modify header information - headers already sent in Unknown on line 0

I changed

always_populate_raw_post_data = -1 

in php.ini file

Now the error message is not appearing but the code still not working on clicking submit button the text in text area is erased and no output is produced using phpstorm ide and php 5.6.32

this also not working

   <?php
      error_reporting(E_ALL);ini_set('display_errors',1); 
     ?>
    <form method="POST">
    <textarea name="user_input" rows="6" cols="30"> </textarea>
    <br>
    <br>
    <input type="submit" value="Submit">

    </form>
    <?php

       if (isset($_POST['user_input'])){
       echo "THIS WORKS!!!";
       }
    ?>
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
Piyush Verma
  • 51
  • 1
  • 7
  • FYI: http://stackoverflow.com/q/4559925/476 – deceze Jun 24 '16 at 09:21
  • ` ` -> what can you see? – xAqweRx Jun 24 '16 at 09:31
  • string(14) "user_input=+aa" – Piyush Verma Jun 24 '16 at 09:33
  • Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream instead. in Unknown on line 0 Warning: Cannot modify header information - headers already sent in Unknown on line 0 – Piyush Verma Jun 24 '16 at 10:10
  • this error appears if always_populate_raw_post_data = -1 is commented in php.ini file. and 'THIS WORKS' is also not printed on screen if i uncomment always_populate_raw_post_data = -1 in php.ini then no error message is displayed but 'THIS WORKS' is also not printed on screen – Piyush Verma Jun 24 '16 at 10:11

1 Answers1

0

Found a solution to this problem

first changed

always_populate_raw_post_data = -1  

in php.ini

second added

parse_str(file_get_contents("php://input"), $_POST)

before if statement

Piyush Verma
  • 51
  • 1
  • 7