PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 24th, 2012, 09:14 AM
rashid1000 rashid1000 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 8 rashid1000 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 40 m 4 sec
Reputation Power: 0
Saving Special Characters along with Line Breaks

Hi

I am using the php to inserting the records in mysql table. My table has following feilds

id int auto increament
data longtext

via php i am inserting the record

PHP Code:
 $data         = isset($_REQUEST['data'])?$_REQUEST['data']:""

   if (isset(
$_REQUEST['submit']))       
   { 
    
      
$data=htmlentities(mysql_real_escape_string($data));     
      
$query=mysql_query(insert into special values($data)); 




and when I echo this record after retrieving from table its shows me in Single Line whatever user input in multiple lines or in a paragraph with some special characters also.

PHP Code:
 $result1=mysql_query("select * from special"); 
        if (
mysql_num_rows($result1)){ 

                     while(
$row=mysql_fetch_array($result1)){ 

                
$str=$row['data']; 
  
  
         
$str=html_entity_decode(stripslashes($str)); 

         echo 
"<textarea>".$str."</textarea>"
         } 


          
          
         } 


I want to show in a original data whats the user actually insert.Can any body help me in this matter.

Thanks

Reply With Quote
  #2  
Old November 24th, 2012, 10:26 AM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Lost in code
Click here for more information.
 
Join Date: Dec 2004
Posts: 7,939 E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 9 h 12 m 42 sec
Reputation Power: 7053
Don't call htmlentities here:
Code:
$data=htmlentities(mysql_real_escape_string($data));


Don't call html_entity_decode or stripslashes here:
Code:
$str=html_entity_decode(stripslashes($str));


DO call htmlentities here:
Code:
echo "<textarea>" . htmlentities($str, ENT_QUOTES, 'UTF-8') . "</textarea>";


When you output newlines into a textarea they should be preserved. If you have a string that you want to show elsewhere in HTML and you want to preserve newlines in it, then you need to convert them into <br />'s. You can do this easily using nl2br().
__________________
PHP FAQ
How to program a basic, secure login system using PHP

Quote:
Originally Posted by Spad
Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

Reply With Quote
  #3  
Old November 24th, 2012, 11:49 AM
rashid1000 rashid1000 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 8 rashid1000 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 40 m 4 sec
Reputation Power: 0
Thanks for your reply Now I tried to use this codes as below
for Inserting
PHP Code:
 $data=mysql_real_escape_string($data); 


and for view as the same like
PHP Code:
echo "<textarea cols='50' rows='10'>" htmlentities($strENT_QUOTES'UTF-8') . "</textarea>"


but unfortunately the result is the same let suppose If I enter this type of insertion in different lines:

Hello how are you
this "is not" and how much
you get' and own

The result is showed in single line:
Hello how are you\r\nthis \\is not\\ and how much\r\nyou get\' and own

Hope you understand my point

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Saving Special Characters along with Line Breaks

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap