June 6, 200818 yr I'm currently using this to enter data into the table: eg1 $w = mysqli_real_escape_string($dbc, trim($_POST['welcome'])); eg2 $w = mysqli_real_escape_string($dbc, str_replace("\\r\\n",'<br>',trim($_POST['welcome']))); eg3 $w = mysqli_real_escape_string($dbc, nl2br(trim($_POST[welcome]))); this re displays the data after entering it (in the editing box): $row = mysqli_fetch_array ($r, MYSQLI_NUM); Welcome: <br /><textarea name="welcome" rows="10" cols="50" value= >' . $row[0] . '</textarea> This is used to display it when referring to it in the 'news' section of the website: $q = "SELECT news AS n, welcome AS w FROM body_text"; $r = @mysqli_query ($dbc, $q); if ($r) { while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { echo '<h1>Welcome</h1>'; echo $row['w']; //'</td><td align="left">' . $row['n'] . '</td></tr> Most of the inputs are in sentence form. I want to keep formatting if the entered data has carriage returns, I would like simple HTML if the user chose to use these (bold, italics and links etc), and I want to make it (fairly) secure. eg1 is no good as it adds / and there is no HTML formatting or returns. eg2 is ok but you have to manually put in the html formatting for carriage returns eg3 is almost there, in the editing box it replaces the returns with <br />. If you update the text again it adds another <br /> to and returns which is no good. eg: enter this: hello welcome to this site Looks like this in the text box after updating: hello <br /> welcome to this site But if you were to make another change (add 'everyone') it looks like this: hello everyone <br /> <br /> welcome to this site Both eg 2 and 3 look correct in the final display in the website (apart from the increasing number of carriage returns). All I want to do is keep formatting if the entered data has carriage returns, have simple HTML and not be too insecure. Phew ... any help ...?
Create an account or sign in to comment