Jump to content

[SOLVED] force br on data output.


peranha

Recommended Posts

When I insert data into my database, it is put in just as it was typed.  on output, the data all runs together in one single line.  How do I force a br in the data?

 

ex.

line 1

line 2

line 3

 

outputs as

 

line1line 2line3

 

This is the code that I use to insert data to the database.

 

$update = clean_data($_POST['update']);

$query = "INSERT INTO " . $pre . "updates (upddate, upddone) VALUES ('{$date}', '{$update}')";

$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

 

Here is the code to display the output from the database.

 

$query = "SELECT upddate, upddone FROM bsc_updates ORDER BY upddateid desc $limit";

$result = mysql_query($query) or die ("<b class='red'>There are no updates on record.</b>");

if (mysql_num_rows($result) > 0) {
    while($row = mysql_fetch_row($result)) {
        echo $row[0] . '<br />';
        echo stripslashes($row[1]) . '<br />';
    }
}

Link to comment
https://forums.phpfreaks.com/topic/111440-solved-force-br-on-data-output/
Share on other sites

This is my clean_data function

 

// Data cleaning function to clean data before inputing to database.
function clean_data($string) {
$string = addslashes($string);
$string = htmlspecialchars($string);
        $string = mysql_real_escape_string($string);
        return $string;

 

Should it be something different.

If you have magic_quotes ON that will add slashes, then you call addslashes() and then you add them yet again with mysql_real_escape_string()

try

function clean_data($string) {
  $string = get_magic_quotes_gpc() ? stripslashes($string) : $string;
  $string = htmlspecialchars($string);
  $string = mysql_real_escape_string($string);
  return $string; 
}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.