Jump to content

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; 
}

 

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.