peranha Posted June 23, 2008 Share Posted June 23, 2008 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 More sharing options...
Barand Posted June 23, 2008 Share Posted June 23, 2008 www.php.net/nl2br And if you're having to strip slashes from your DB data then the clean_data() function is wrong. Link to comment https://forums.phpfreaks.com/topic/111440-solved-force-br-on-data-output/#findComment-572054 Share on other sites More sharing options...
peranha Posted June 23, 2008 Author Share Posted June 23, 2008 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. Link to comment https://forums.phpfreaks.com/topic/111440-solved-force-br-on-data-output/#findComment-572146 Share on other sites More sharing options...
Barand Posted June 23, 2008 Share Posted June 23, 2008 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; } Link to comment https://forums.phpfreaks.com/topic/111440-solved-force-br-on-data-output/#findComment-572171 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.