Jump to content


Photo

Guestbook


  • Please log in to reply
4 replies to this topic

#1 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 29 June 2006 - 06:46 PM

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...ml4/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\" /]
How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#2 Buyocat

Buyocat
  • Members
  • PipPipPip
  • Advanced Member
  • 267 posts

Posted 29 June 2006 - 06:53 PM

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.
Looking for some easy-to-use tools?  Try these, https://sourceforge....jects/utils-php -- I made them myself.  They're distinct tools which are easy to understand and use.  See some examples uses at http://www.anotherearlymorning.com

#3 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 29 June 2006 - 06:59 PM

[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
How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#4 Buyocat

Buyocat
  • Members
  • PipPipPip
  • Advanced Member
  • 267 posts

Posted 29 June 2006 - 07:04 PM

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.
Looking for some easy-to-use tools?  Try these, https://sourceforge....jects/utils-php -- I made them myself.  They're distinct tools which are easy to understand and use.  See some examples uses at http://www.anotherearlymorning.com

#5 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 29 June 2006 - 07:20 PM

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
How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users