I have created a form
<form name="form1" method="post">
<textarea rows="5" cols="20" name="ta1"></textarea>
<input type="submit" name="submit" />
<textarea rows="5" cols="20"><?php echo $_POST['ta1']; ?></textarea>
</form>
And a PHP code
<?php
if ($_POST['submit']) {
$llo = $_POST['ta1'];
$con1 = mysql_connect("localhost", "FreeUser", "123456");
mysql_select_db("database", $con1);
mysql_query("insert into test (ttta) values ('$llo')");
$q1 = mysql_query("select * from test");
$res = mysql_fetch_array($q1);
echo $res['ttta'];
}
?>
Database table test
id Auto_Increment
ttta mediumtext 500
only two fields in table
Now when i type something in textarea as formatted below
Rafee
Web Developer
XYZ Company
New York
When i press the submit button, same content with same formatting structure in stored / displayed in database table / textbox
But when i echo
this value its displaying in single line without any format.
How can we achived this.
And i have added an image for better understanding
Use
echo nl2br($res['ttta']);
That will convert \n
into the HTML tag <br />
In HTML, visible line brakes requires the use of the HTML tag <br />
, but in your PHP, the stored data is "Rafee\nWeb Developer\nXYZ Company\nNew York\n"
, so you need the function to turn "\n"
into "<br />"
.
Reference: http://php.net/manual/en/function.nl2br.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With