I have now got the formatting working the way I want it to work. It looks like I will need to make amends to several other sites that I have developed too to deal with formatting like this.
Anyway before I do so, I would appreciate any comments on whether the following is the correct way to do this.
Ensure Magic quotes is off
For my edit page use the following code:
Code:
<?php
if ($_POST["submit"]) {
$accommodationId = $_GET["accommodationId"];
// ------------------------
// Get all form data values
// ------------------------
$description = $_POST["description"];
// -------------------------------------------------------
// Check if any of the required fields have not been filled in
// -----------------------------------------------------------
if(trim($description)=='') {
$arrErrors['description']="Please enter the description of your accommodation<br>";
}
if (count($arrErrors) == 0) {
$query = "UPDATE accommodation SET description='" .mysql_real_escape_string($description) . "'
WHERE id ='" .mysql_real_escape_string($accommodationId) . "'";
mysql_query($query) or die(mysql_error());
mysql_close();
}
}
Then on the same page in the form area where the user can edit the description have the following:
Code:
<textarea name=description wrap=physical rows=10 cols=47 ><?php echo str_replace(array('\r', '\n'), array(chr(13), chr(10)), $description); ?></textarea>
Finally on the page that I actually display the description as part of a listing the following
Code:
$description = $row->description;
$description = nl2br($description);
All advice much appreciated.
Thanks
Paul
Bookmarks