jeff5656 Posted November 11, 2008 Share Posted November 11, 2008 I have a text box. If a user hits carriage return I want to retain that and store that in the database. However, it all gets displayed as one line: here's the form: <th><div align="left">Active Problem List</div></th> <td><textarea name="problist" id="problist" cols="45" rows="3">1. 2.</textarea></td> Here is me inserting it into the database: $problist = $_POST['problist']; ..... $query = "INSERT INTO icu (id_incr, rm_loc, pod, patient, mrn, age, race, gender, rcf_date, rcf_date2, dx, meds, pmhx, problist, problist_date, anticipate, anticipate_date, antic2, antic3, antic4, antic2_date, antic3_date, antic4_date, todo, todo2, todo3, todo4, todo_date, todo2_date, todo3_date, todo4_date, comments, comments_date, code, allergy, signoff_status) VALUES('$id_incr','$rm_loc', '$pod', '$patient', '$mrn', '$age', '$race', '$gender', '$rcf_date', '$rcf_date2', '$dx', '$meds','$pmhx', '$problist', '$problist_date', '$anticipate', '$anticipate_date', '$antic2', '$antic3', '$antic4', '$antic2_date', '$antic3_date', '$antic4_date','$todo', '$todo2', '$todo3', '$todo4','$todo_date', '$todo2_date', '$todo3_date', '$todo4_date', '$comments', '$comments_date','$code', '$allergy','a')"; Here is the display the reads as one line (but does word wrap) <td bgcolor="#FFFFFF" valign="bottom"> <?php echo $row['problist']; echo "<p align='right' style='font-family:verdana;font-size:65%;color:red'>"; echo "Updated "; echo date("m/d/Y @ H:i", strtotime($row['problist_date'])); echo "</p>"; Quote Link to comment https://forums.phpfreaks.com/topic/132346-solved-retain-a-carriage-return-from-a-text-box/ Share on other sites More sharing options...
premiso Posted November 11, 2008 Share Posted November 11, 2008 www.php.net/nl2br Chances are it is kept, just html requires it to be converted to a <br> tag to display it. Before echoing out the item you want to display the break try wrapping it in the nl2br function. Hope that helps. Quote Link to comment https://forums.phpfreaks.com/topic/132346-solved-retain-a-carriage-return-from-a-text-box/#findComment-688095 Share on other sites More sharing options...
DarkWater Posted November 11, 2008 Share Posted November 11, 2008 nl2br(); EDIT: Beaten to it. Quote Link to comment https://forums.phpfreaks.com/topic/132346-solved-retain-a-carriage-return-from-a-text-box/#findComment-688096 Share on other sites More sharing options...
wildteen88 Posted November 11, 2008 Share Posted November 11, 2008 Haha! #3 Look into using nl2br echo nl2br($row['problist']); all newlines are stored in the database. Its the web browser that ignores the new lines. Quote Link to comment https://forums.phpfreaks.com/topic/132346-solved-retain-a-carriage-return-from-a-text-box/#findComment-688097 Share on other sites More sharing options...
jeff5656 Posted November 11, 2008 Author Share Posted November 11, 2008 Great, that did the trick <?php echo nl2br ($row['problist']); Thanks guys! Quote Link to comment https://forums.phpfreaks.com/topic/132346-solved-retain-a-carriage-return-from-a-text-box/#findComment-688125 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.