I'm trying to store the text from my textarea into my php variable, but it seems like it is not working as i wish too. and it shows error in my textarea:

<br />
<b>Notice</b>: Undefined index: ftext in <b>C:\Program Files (x86)\EasyPHP-5.3.9\www\sentiform.php</b> on line <b>20</b><br />

sorry that i am not very good in php yet. I am using button, not the input type = "submit" button.
below is my code

<title>Test Sentiment</title>


$comment = ' ';

<form name = "SentimentForm" method = "POST" action=>
Input text: <textarea name ="ftext" rows = "10" cols = "50"><?php $comment = $_POST['ftext']; ?></textarea>

<?php echo $comment; ?>
<input type= "button" value = "Send" name = "btn1" onclick="sentiform.php" >


hope that someone here can guide me to my mistake.

A few things

  1. Why are you using an onclick function to submit your form when there is no need as you are not doing anything complex, just submitting it?
  2. If you are using onclick instead of submit you need to completely remove the action= from your form tag
  3. Where are you assigning your $_POST['ftext'] to your $comment variable as I can't see anywhere and therefore the $comment variable will still be empty as the original declaration?

Looking at your code, this is how I would have it:

$comment = ' ';

if (isset($_POST) && !empty($_POST['ftext'])) {
    $comment = $_POST['ftext'];

<form name = "SentimentForm" method = "POST" action='sentiform.php'>
Input text: <textarea name ="ftext" rows = "10" cols = "50"><?php if(!empty($comment)) { echo $comment; } ?></textarea>
<input type= "submit" value = "Send" name = "btn1">
<?php if (!empty($comment)) { echo $comment; } ?>