Jump to content
techker

insert text from text box as is?

Recommended Posts

Hey guys i have a for to upload for a car dealership i did ,in the form there is a text box for descrption.

 

the guy wants to be able to insert a description like:

 

...........................

 

this is a car test

 

.features one

.features 2

.......

 

this car is fully equipeed...

 

..........................

 

but now the form insert in the database all messt up it becomes one text...

 

 

is there a way to insert it in the database as he puts it?

Share this post


Link to post
Share on other sites

HTML treats all whitespace (including newlines) as a single space.

 

When outputting text with newlne chars, use nl2br($text) to insert the <br> tags required by HTML

Share this post


Link to post
Share on other sites

so the output would be

$string = ".echo row['description'];.";
echo nl2br($string);

Share this post


Link to post
Share on other sites

Unless your doing something to the data before it goes into the database, all those newlines are there.

 

So as mentioned, the problem is probably when you display. nl2br() will help here, but you should also use htmlentities(). This will ensure anything typed into the box is displayed exactly as typed and not evaluated as HTML.

 

echo nl2br(htmlentities($row['description']));

 

The takeaway here is that you process the data for where it's going. If it's going on the database, process through a prepared statement. If it's going into an HTML document, process it as above. If it's going into email, maybe there's another processing. etc, etc.

 

Process for where it's going at the time it goes there. i.e. don't prices for HTML as it goes into the database.

 

Hopefully that helps.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.