Jump to content

insert text from text box as is?


techker

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?

Link to comment
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.