I have a post form with a text area in it. When I save the text from my textarea into mysql db, the text is saved with some white spaces before and after my actual test.
Why is happening this? How can I overcome this?
Thanks in advance
There's probably whitespace in your markup. For example:
<textarea>
<?php echo ($textareavalue); ?>
</textarea>
You could either remove the whitespace
<textarea><?php echo ($textareavalue); ?></textarea>
Or you could trim() the input before storing it to the database
$_POST ['textareavalue'] = trim ($_POST ['textareavalue']);
If you have code like this:
<textarea name="foobar">
<? echo $contents; ?>
</textarea>
Then you are adding whitespace to the value before/after the <? ... ?> tags (note, php does try to remove whitespace in some situations, so sometimes you can get away with it).
The fix is to do this:
<textarea name="foobar"><? echo $contents; ?></textarea>
<textarea></textarea>?