Reputation: 169
okay so i have a form field that you can click enter and it indents to a new line and once you submit that text it goes into mysql database and i wanted to know how can i echo the text with the indents?
example:
i enter text like this :
"hello
how have you been"
and it echos out like this :
"hello how have you been"
php to echo code:
<?php if (isset($comments)) {
while ($rowrr = $comments->fetch_assoc()) {
echo "<div><p>" . $rowrr['comment'] . "</p></div>";
}
} ?>
HTML CODE text field:
<form action="" method="POST" onsubmit="return insert_value()">
<input id="hidden_data" name="data" type="hidden" value=""/>
<div id="showing_data" class="commenttext" contenteditable="true"></div>
<input type="submit" value="Enter" id="submitthis" />
</form>
Mysql Code to insert text field text:
if (isset($_POST['data'])) {
$var2 = urldecode($_POST['data']);
$stmt = $dbconn->prepare("INSERT INTO photocomments (user_id, comment) VALUES (?, ?)");
$stmt->bind_param('is', $user_id, $var2);
$stmt->execute();
}
Upvotes: 0
Views: 518
Reputation: 2333
Would an HTML <pre>
tag be useful here? It preserves white-space and line breaks.
http://www.w3schools.com/tags/tag_pre.asp
Upvotes: 2