Solved

Textarea to MySQL adds tab

Posted on 2013-01-19
8
323 Views
Last Modified: 2013-01-28
When saving the contents of a textarea to MySQL into a blob field using PDO I get 6 tabs added to the beginning of the data and 4 tabs added to the end (that is tabs as in if you pressed the TAB key)
Is there something special I should be doing for a textarea?
This is a just a normal prepare statement followed by execute(array etc and assigning the post value of the textarea to a value for the prepare statement.
':description' => $_POST['description']

The posted data does not contain the tabs - I checked by echoing out the post value.
0
Comment
Question by:Gary
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 38797549
Uhh, not sure but have you tried trim() right before preparing the data element?
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38797557
Echoing the data in HTML is misleading because HTML ignores tabs and other control characters.  It may display them as a space.
0
 
LVL 58

Author Comment

by:Gary
ID: 38797661
Already tried trim to no effect
@Dave
But in an editor they still should show - which they don't...
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 11

Expert Comment

by:mcnute
ID: 38798225
Have you tried this:

$text = preg_replace("/\s+/", " ", $text);  

Open in new window


Where $text is your $_POST['description']; variable
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 38798297
If trim($_POST['description']) did not do the job, then I think we need to see a little more deeply into the problem.  Can you determine exactly when the addition of the tabs occurs?  For example, if you use phpMyAdmin to examine the data base do you detect the tabs in the column?  If you change the column type to TEXT does the problem still present?  Can you produce the SSCCE so we can install a parallel script and try it on our servers?
0
 
LVL 58

Accepted Solution

by:
Gary earned 0 total points
ID: 38799148
Found the problem - there were tabs before and after <?=$description?> which were being added into the textarea.  

Stupid I know...
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38799397
Glad you found it.
0
 
LVL 58

Author Closing Comment

by:Gary
ID: 38826207
Realised my own stupidity
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question