Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php not recreating paragraphs 1

Status
Not open for further replies.

kzn

MIS
Jan 28, 2005
209
GB
Hi

I am having a problem and I can not work out how to solve this.

I have one page that inserts text into a mysql table.If I look in mysql front, I can see the data and it shows the paragraphs. However when I call the data to show on a new page, the paragraphs disapear.

If I had inserted the above 2 paragraphs it would show as follows: I am having a problem and I can not work out how to solve this.I have one page that inserts text into a mysql table.If I look in mysql front, I can see the data and it shows the paragraphs. However when I call the data to show on a new page, the paragraphs disapear.

Does anyone know how I can sovle this. Below is the code. Thanks in advance for any help.

######## insert file #####################
<?php
if(isset($_POST['submitted'])) {
if(!empty($_POST['content'])) {
$content =trim($_POST['content']);
} else {
echo "Enter some text please.";
}


if($content) {
$query="insert into data (content) values ('$content')";
$result=mysql_query($query);
}

echo $query;

if(mysql_affected_rows == 1) {
echo "Added";
}

}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="insert_data.php" method="post">
<textarea name="content" rows="5" cols="40"></textarea>
<input type="submit" name="submit" value="Add" />
<input type="hidden" name="submitted" value="true" />
</form>
</body>
</html>


######### display file ###########################
<?php

$query = "select * from data limit 1";
$result = mysql_query($query);

$row=mysql_fetch_row($result);




?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<div>
<?php
echo $row[1];
?>
</div>
</body>
</html>



Any help would be appreciated ... thank you
 
this is the difference between source code and html. white space is ignored in html so you have to convert paras to breaks.

change this line as shown.

Code:
echo [red]nl2br([/red]$row[1][red])[/red];
 
Thank you very much Jpadie and thanks for the explanation.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top