Hi there, got some issues with my guestbook and would use some help๐
While I understand if this wasn't the mest easy to read...but i think it looks better now, so please...
<?php
require "connection.inc"
$name = trim($_POST["text_name"]);
$name = htmlentities($name);
$name_length = strlen($name);
$email = $_POST["text_email"];
if ($name_length > 0)
{
if (valid ($email))
{
$comment = $_POST["text_comment"];
$date = time();
connection();
$query = "INSERT INTO guestbook (autoID, name, email, comment, date_auto) VALUES (NULL, '$name', '$email', '$comment', '$date')";
mysql_query($query, $connection) or die ("database query failed!");
exit;
}
else
{
echo "<textarea name='comment'>Enter a Valid name and/or a valid email adress</textarea>";
}
}
[B]Here is my first problem, the textarea generated is made in a new textboxt, i want it to show up in my "comment-box". I would also like an error message when no comment is posted[/B]
?>
<html>
<head>
<title>My Guestbook</title>
<link href="Untitled-1.css" rel="stylesheet" type="text/css">
</head>
<body>
<center>
<fieldset>
<legend>
Enter your details:
</legend>
<form action="<?php echo $_SERVER[PHP_SELF]; ?>" method="POST">
<font face="arial" size="1">
Name: <input type="text" name="text_name">
Email: <input type="text" name="text_email"><br><br>
comment:<br>
<textarea style="width: 75%" rows="10" name="text_comment"></textarea>
<center><input type="submit" value="Submit"></center>
</font>
</form>
</fieldset>
<table bgcolor="#AAAAAA" border="0" width="75%" cellspacing="1" cellpading="2">
<?php
$query = "SELECT * From guestbook ORDER BY date_auto";
$result = mysql_query($query, $connection);
for ($i = 0; $i < mysql_num_rows($result); $i++)
{
$name = mysql_result($result, $i, "name");
$email = mysql_result($result, $i, "email");
$email_length = strlen($email);
$match=array(" :/",":)",";)",":D",":(",":P","(cool)",":-)",";-)",":p",";-F");
$replace=array( "<img src=\"emoticons/5.gif\">",
"<img src=\"emoticons/2.gif\">",
"<img src=\"emoticons/3.gif\">",
"<img src=\"emoticons/4.gif\">",
"<img src=\"emoticons/5.gif\">",
"<img src=\"emoticons/6.gif\">",
"<img src=\"emoticons/7.gif\">",
"<img src=\"emoticons/8.gif\">",
"<img src=\"emoticons/9.gif\">",
"<img src=\"emoticons/10.gif\">",
"<img src=\"emoticons/11.gif\">"
);
$comment = mysql_result($result, $i, "comment");
//Will type with newline properly
$comment = nl2br($comment);
$date = mysql_result($result, $i, "date_auto");
$date = date("H:i:s d/m/Y", $date);
if ($i % 2)
{
$bg_color="#EEEEEE";
}
else
{
$bg_color="BAC4D5";
}
echo '
<tr>
<td width="100%" bgcolor="'.$bg_color.'">
<font face="arial" size="2">';
if ($email_length > 0)
{
echo '<b>Name:</b> <a href="mailto:'.$email.'">'.$name.'</a>';
}
else
{
echo '<b>Name:</b> '.$name;
}
echo '
<br>
<b>comment:</b> '.str_replace($match,$replace,$comment).'
</font>
<td>
<td width="1%"valign="top" nowrap bgcolor="'.$bg_color.'">
<font face="arial" size="2">
<b>Date: </B> '.$date.'
</font>
</td>
</tr>
';
}
?>
</table>
</center>
<br>
<br>
</body>
</html>
connection.inc
<php
function connection($connection){
$connection = mysql_connect("localhost", "wingman", "12345678") or die(mysql_error());
mysql_select_db("forum", $connection);
}
?>