Yinks
Yinks

Reputation: 203

Text Area spacing when inserting to database

so i have this Text area wherein the data will be posted to the database.

enter image description here

so here is an image of what my sample input might look like.it has spacing via enter key but when it is send to the database the spacing wont be there and the display of the input will be

enter image description here

<?php
    require("common.php");
    if(empty($_SESSION['user']))
    {
        header("Location: login.php");
        die("Redirecting to login.php");
    }
?>
<?php

$host="localhost";
$username="root";
$password=""; 
$db_name="phplogin"; 
$tbl_name="tasks"; 

mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$Ttoday=$_POST['comment1'];
$task_issues=$_POST['comment2'];
$Ttom=$_POST['comment3'];
$id=$_POST['comment'];

$sql="INSERT INTO $tbl_name(task_today, issues, task_tom, U_ID)VALUES('$Ttoday', '$task_issues', '$Ttom', '$id')";
$result=mysql_query($sql);

if($result){
header("Location: private.php");
exit;
}

else {
echo "ERROR";
}
?>

<?php
// close connection
mysql_close();
?>  

here is my insert codes.

Upvotes: 0

Views: 282

Answers (1)

Edwin Alex
Edwin Alex

Reputation: 5108

Use nl2br(). Try this,

$Ttoday= nl2br($_POST['comment1']);

Upvotes: 1

Related Questions