Hi there.
In trouble again. I had a look around but could not find the right solution.
I have a blog that saved the blog entries into a MySQL database.
A form transfers the data into the databse:
Form:
<form action="../ok.php" method="post" name="insert" class="form" id="insert">
<p><label for="title">Title
<input name="title" type="text" class="form" id="title" size="60" maxlength="250" ></label></p>
<p><label for="text">Text
<textarea name="text" cols="60" rows="16" class="form" id="text"></textarea></label></p>
<p><label for="author">Author
<input name="author" type="text" class="form" id="author" size="60" maxlength="100" ></label></p>
<label>
<input type="submit" name="send" id="send" value="Submit" >
</label>
</form>
Database:
$day = date('d');
$month = date('m');
$year = date('Y');
$h = date('G');
$m = date('i');
mysql_select_db (DB_NAME);
if (!$dbc)
{
die('Could not connect: ' . mysql_error());
}
$sql="INSERT INTO nimtazblog (title, text, author, day, month, year, h, m)
VALUES ('$_POST[title]','$_POST[text]','$_POST[author]', $day, $month, $year, $h, $m)";
if (!mysql_query($sql,$dbc))
{
die('Error: ' . mysql_error());
}
;mysql_close($dbc)
then the data is saved into the databased and there it is displayed in separate lines.
When I try to get the data from the database but It then prints my text field in a signle line instead of printing it in multiple lines.
This is my code:
$query = "SELECT * FROM nimtazblog ORDER BY entryid DESC ";
$result = mysql_query($query);
$entryid=$row['entryid'];
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "<h2 style='margin-bottom:-10px; margin-top:15px; color:#c993be'>{$row['title']} </h2>";
echo "<p style='line-height:10px; color:#813f74'>posted by {$row['author']} on {$row['day']}/{$row['month']}/{$row['year']}, at {$row['h']}:{$row['m']} </p>" ;
echo " <p class='txt' style='line-height:10px;'>{$row[$text]}<br>";
I've read of the nl2br so I've tried assigning my row result for the text field to a variable
$text=$row['text'];
;
and then try to print my results this way:
echo " <p class='txt' style='line-height:10px;'>"nl2br($text)"<br>";
but I am not getting it right..
Do you guys know what I'm doing wrong?
Thanks again!
Morena