Jump to content

Recommended Posts

This must be a common problem - or maybe I am doing it wrong.

 

When I use create a record using a textarea in a form and insert it into my table the returns are invisable.

 

Eg:

---------------------

Peter looking for a low-cost, yet highly effective means of advertising your products and services, then Google AdWords may be your answer.

 

Google AdWords provides a simple way to purchase highly targeted advertising , regardless of your budget. Unlike other sites selling banner ad space and pay-per-ranking, AdWords provides advertisers with highly effective text ads that are displayed with the search results. Studies have shown that highly targeted keyword advertising produces an average of four times the industry standard clickthrough rate.

 

Google, one of the premier Search Engines, receives over 29 million searches each day.

---------------------

 

 

When I veiw the database record they are also invisable yet the formatting stays the same so they are there (some how).

 

I then come to edit/modify the record an if the modifcation contains an error (like the heading is missing) and the record needs to be re-displayed, then I get this kind of display:

 

---------------------

Peter looking for a low-cost, yet highly effective means of advertising your products and services, then Google AdWords may be your answer.\r\n\r\nGoogle AdWords provides a simple way to purchase highly targeted advertising , regardless of your budget. Unlike other sites selling banner ad space and pay-per-ranking, AdWords provides advertisers with highly effective text ads that are displayed with the search results. Studies have shown that highly targeted keyword advertising produces an average of four times the industry standard clickthrough rate.\r\n\r\nGoogle, one of the premier Search Engines, receives over 29 million searches each day.

---------------------

 

If I save this version then the "\r\n\r\n" get recorded as well - ie they are not invisable any more.

 

How can I stop these \r\n\r\n's from showing up ?

It seems odd that they don't show up in a straight forward edit - only when there is a mistake and a re-display occurs.

 

This is my safe_sql function:

 

// Make variable SQL safe
function safe_sql( $value )
{
     $value = strip_tags(trim($value));
         
    // Stripslashes
    if (get_magic_quotes_gpc()) {
        $value = stripslashes($value);
    }
    // Quote if not integer
    if (!is_numeric($value)) {
        $value = mysql_real_escape_string($value);
    }
    return $value;
} // End of Function 

 

 

And here is my form process:

 

if(isset($_POST['tutedit']))  {
    $N_art_head  = safe_sql($_POST['x_art_head']);
        $N_art_body  = safe_sql($_POST['x_art_body']);
/*
*  Check for blanks.  
*/        

if ( $N_art_head == "" || $N_art_head  == " "){
    $err_mes = "The article title appears to be missing!";             
    require_once ("write_tute_fm.php");
    exit(); 
   }  // endif
                

if ( $N_art_body == "" || $N_art_body  == " "){
    $err_mes = "The entire article body is missing!";             
    require_once ("edit_tute_fm.php");
    exit(); 
}  // endif 

 

And the form is here:

 

 

<div class="art_title">
        <label for="x_art_head">Title: </label>
        <input class="data1" type="text" name="x_art_head" size="40" value = "<?php echo $N_art_head ?>" >
        <span style ="color : red; " > <?php echo "$err_mes"; ?></span>
    </div>
    
    <div class="art_title">
        <label for="x_art_body">Content: </label>
        <textarea class="data1" rows="24" cols="80" name="x_art_body" >
        <?php echo $N_art_body ?></textarea>
    </div>

 

I am not sure if I should replace the \r\n with <br> for the re-display or will that make things worse ?

 

I have now tried added nl2br($N_art_body); just before the re-display

and Now it shows up with the HTML in it, like this:

 

-----------------

Peter looking for a low-cost, yet highly effective means of advertising your products and services, then Google AdWords may be your answer.<br />

<br />

Google AdWords provides a simp

------------------

 

I don't think thats what I wanted - I just wanted the formatting to stay in place

 

Since I am using the $value = strip_tags(trim($value)); when taking the POST data I don't think I need to use htmlspecialchars as there shouldn't be any tags left

 

- but maybe I should do that as well just before the db save ??

 

 

Any ideas on solving this problem greatly appreciated  :)

 

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.