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

<html>
<head>
<title>Test Sentiment</title>

</head>
<body>
<?php

$comment = ' ';

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

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

</form>
</body>
</html>

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:
<?php

$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">
</form>
<?php if (!empty($comment)) { echo $comment; } ?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.