Page 1 of 1
<textarea> output with <br>
Posted: Sat Oct 25, 2008 6:41 am
by vinpkl
hi all
i would like to ask that i have a <textarea> and in that i can insert 3 lines. i want to that 3 lines ouput should come with a break after each line. means i just want to add <br> after each line ouput.
the name of <textarea> is shipping_detail.
Code: Select all
$shipping_detail=$_REQUEST['shipping_detail'];
Re: <textarea> output with <br>
Posted: Sat Oct 25, 2008 7:36 am
by Hannes2k
Hi,
if you hit 'enter' in a textbox, this line break is represented by \n (Unix System) or \r\n (Windows) or \r.
One solution is to replace \r\n, \n and \r by <br>, but the better solution is to use nl2br:
echo nl2br($value_from_textbox);
Re: <textarea> output with <br>
Posted: Sat Oct 25, 2008 7:51 am
by vinpkl
Hannes2k wrote:Hi,
if you hit 'enter' in a textbox, this line break is represented by \n (Unix System) or \r\n (Windows) or \r.
One solution is to replace \r\n, \n and \r by <br>, but the better solution is to use nl2br:
echo nl2br($value_from_textbox);
hi
here is what i tried. but i gets error "error inserting product"
Code: Select all
if(isset($_REQUEST['submit']))
{
$shipping_detail = nl2br($_REQUEST["shipping_detail"]);
$warranty=$_REQUEST['warranty'];
$insertqry="insert into product_table(shipping_detail,warranty) values('$shipping_detail','$warranty')";
if(mysql_query($insertqry))
$msg="shipping Product added successfully";
else
$msg="Error Inserting new product";
}
but this doesnt work.
If i m wrong then correct me. do i have to add nl2br where i m writing echo $value in my page or where i have inserted it in my above code.
i m little confuse.
Re: <textarea> output with <br>
Posted: Sat Oct 25, 2008 8:11 am
by Hannes2k
Hi,
no, I is better to use nl2br only on the output. Just insert the orginal value into your database and when you use echo to present this data, use nl2br().
But that's not the problem of your mysql-error.
Better try this:
if(mysql_query($insertqry))
echo "shipping Product added successfully";
else
echo die("Error Inserting new product ".mysql_error());
The mysql_error() shows you the error in your statement, so you can fix it.
Re: <textarea> output with <br>
Posted: Sat Oct 25, 2008 8:16 am
by vinpkl
Hannes2k wrote:Hi,
no, I is better to use nl2br only on the output. Just insert the orginal value into your database and when you use echo to present this data, use nl2br().
But that's not the problem of your mysql-error.
Better try this:
if(mysql_query($insertqry))
echo "shipping Product added successfully";
else
echo die("Error Inserting new product ".mysql_error());
The mysql_error() shows you the error in your statement, so you can fix it.
hi
thanks for the solution. its now fine.
i used nl2br where i have written echo $value and it worked perfect.
vineet