Jump to content

Textarea does not show line breaks after being added


joesoaper

Recommended Posts

I have a textarea for notes. When I enter or paste text into this field it all shows on one line. For example I enter

 

Line 1

Line 2

Line 3

 

 

When it is updated it shows as  - Line 1 Line 2 Line 3 -  while I actually want it to show as it was originally copied or pasted in.

 

After several days of trying different options I am stumped.

 

This is the code I am using currently is as follows:

include("connect.php");


$uniq = $_GET['uniq'];
$staff = $_POST['staff'];
$notes = $_POST['notes'];
$notesupdated = $_POST['notesupdated'];
     

$result = mysql_query("SELECT * FROM new_notes WHERE uniq = '$uniq' ORDER BY notesupdated ASC");
$num = mysql_num_rows ($result);

if ($num > 0 ) {
$i=0;
while ($i < $num) {

    
   
    $unik = stripslashes(mysql_result($result,$i,"unik"));
    $staff = stripslashes(mysql_result($result,$i,"staff"));
    $notes = stripslashes(mysql_result($result,$i,"notes"));
    $notesupdated = stripslashes(mysql_result($result,$i,"notesupdated"));
    
    
   
    
    
    
 $row .= '<tr bgcolor=" #ffffff">
 <td valign="top" width="4">'.$staff.'</td> 
 <td valign="top" width="4">@</td>     
 <td align="left" width="100%">'.$notesupdated.'</td>
 </tr> 
 <tr>
 <td width="400" colspan="5">'.$notes.'</td>
 </tr>'  
;
	
++$i; }} else { $row = '<tr><td colspan="2" align="center">Nothing added yet</td></tr>'; }


?>

As always any help or advice greatly appreciated

Link to comment
Share on other sites

you are displaying the content using html. in html, a new line is a <br> tag. see php's nl2br() function.

 

next, your most recent threads on the forum have been using the php PDO extension. why have you reverted to obsolete and insecure code using the php msyql extension?

Link to comment
Share on other sites

The code is fudged up beyond repair. It was obviously written for the ancient Magic Quotes feature which doesn't even exist today (it was removed back in 2009). Now you're wide open to SQL injection attacks, and the stripslashes() stuff will damage your data.

 

Your HTML markup is even older. Visual attributes like bgcolor were deprecated in 1997! So either the application hasn't been touched in the last 20 years, or you really need to update your knowledge.

 

In any case, expect a major rewrite.

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.