Jump to content

Archived

This topic is now archived and is closed to further replies.

spires

Guestbook

Recommended Posts

Hi,


I'm building a guestbook, which is almost finished.
[a href=\"http://www.spirestest.com/login2/guestbook/\" target=\"_blank\"]My Webpage[/a]

But, when you type into the comments box and hit the return key,
it don't show new lines in the veiw guestbook page?

Everything is on one contiunes line.


Does any one know how to get around this problem?

here is my code.

<?php
include('db.php');
include('validation.php');
?>

<?php

$arrErrors = array();

if (!empty($_POST['submit'])) {
if ($_POST['name'] == "")
$arrErrors['name'] = 'Add Name';
if ($_POST['comments']== "")
$arrErrors['comments'] = "Add Comments";
if ($_POST['email']== "") {
$arrErrors['email'] = 'Add Email';
} else {
if (email_validation($_POST['email'])==true) {
$arrErrors['email'] = 'Email Incorrect Format';
}
}



if (empty($name) || empty($email) || empty($comments)) {
foreach ($arrErrors as $error) {
$strError .= '<div class="error">';
$strError .= "<li>$error</li>";
}
$strError .= '</div>';
}

if (count($arrErrors) == 0) {

$name=$_POST['name'];
$email=$_POST['email'];
$comments=$_POST['comments'];
$link = '<a href="guestbook.php" class="link">Click Here To View Your Post</a>';
$date = date("Y-m-d > H:i:s");

$sql = mysql_query("INSERT INTO guestbook (name, email, date, comments)
VALUES ('$name', '$email', '$date', '$comments')") or die ("could not insert");
if ($sql) {
$ok = 'Your Comments have been posted,<br>'.$link.'';
} else {
$notOk = "Sorry, there was an Error";
}
}

}


?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>GuestBook</title>
<link href="../login.css" rel="stylesheet" type="text/css">
</head>

<body leftmargin="0" topmargin="0">
<center>
<table width="400" align="center">
<tr>
<td align="center">
<?php echo $strError; ?>
<?php echo $ok; ?>
<?php echo $notOk; ?>
</td>
</tr>
</table>
<br>
<form name="form1" method="post" action="<?php echo $PHP_SELF; ?>">
<table class="TLRB_border" bgcolor="#EEEEEE" width="400px" cellpadding="5" cellspacing="0">
<tr>
<td bgcolor="#CCCCCC" colspan="2">
<div class="Title">Please Fill in your details</div>
</td>
</tr>
<tr>
<td>
<div class="loginBox_text">Name:</div>
<input name="name" type="text" id="name" size="15" value="<?php echo $_POST['name']?>">
</td>
<td>
<div class="loginBox_text">Email:</div>
<input name="email" type="text" id="email" size="15" value="<?php echo $_POST['email']?>">
</td>
</tr>
<tr>
<td colspan="2" align="center">
<div class="loginBox_text">Comments:</div>
<textarea name="comments" cols="40" wrap="PHYSICAL" id="comments" value="<?php echo $_POST['comments']?>"></textarea>
</td>
</tr>
<tr>
<td colspan="2" align="right">
<input type="submit" name="submit" value="Submit">
</td>
</tr>
</table>
<table width="400">
<tr>
<td align="center">
<div align="right"><a href="index.php" class="link">Click here to go back to the entrance </a></div>
</td>
</tr>
</table>
</form>
</center>
</body>
</html>

Thanks for your help [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]

Share this post


Link to post
Share on other sites
If I follow you then nl2br() is the function you want to use. It will convert line breaks in the coment box to <br />. This means when the thing is dumped into a HTML wrapper it will have the <br/>'s in it already.

Share this post


Link to post
Share on other sites
[img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]

Cheers mate, thats great. Just what i need.

Where do i place the nl2br() function?


Regards
Jeff

Share this post


Link to post
Share on other sites
Sorry, heh, it goes around what you want to do it to. In this case the comments string. You might try...

$comments = nl2br(trim($_POST['comments']));

I threw in the trim, I suggest using it too, because it removes white space around the string; just keeps things looking nicer...

I didn't check, so sorry if this is superfluous, but be sure to stripslashes before entering data into the database. By the way all these functions can be read up on, and in much detail, at PHP.net. Usually just writing...
php.net/functionname
gets what you want.

Share this post


Link to post
Share on other sites
Cheers mate [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]


Thanks once again.

Regards
Jeff

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.