Let's Cook with Meg and Ted
\n
Comments on: $title
"; } if ($_SERVER["REQUEST_METHOD"] == "POST") { if ($_POST["comment"]) { $comment = trim($_POST["comment"]); $_POST["name"] and $name = trim($_POST["name"]); $_POST["email"] and $email = trim($_POST["email"]); $_POST["url"] and $url = trim($_POST["url"]); /* Construct the query */ $query = "INSERT INTO comment SET label=\"$label\""; if ($name) $query = $query . ", name=\"$name\""; if ($email) $query = $query . ", email=\"$email\""; if ($url) $query = $query . ", url=\"$url\""; if ($comment) $query = $query . ", comment=\"$comment\""; $query = $query . ", time = NOW();"; } else { print "Did you have something to say?\n"; } } /* Connect to the database */ $link = mysql_connect("localhost", $db_user, $db_passwd) or die("Unable to connect to database server" . mysql_error()); /* Choose our database */ mysql_select_db($db_database) or die("Unable to use database: $db_database"); /* Post our comment */ if ($query) { $result = mysql_query($query) or die("Query failed: " . mysql_error()); } /* Query for the complete set of comments */ $result = mysql_query("SELECT UNIX_TIMESTAMP(time), name, email, url, comment FROM comment WHERE label = \"$label\" ORDER BY time") or die("Query failed: " . mysql_error()); $nocomment = 1; while ($row = mysql_fetch_array($result, MYSQL_NUM)) { print "
\n"; $body = nl2br(htmlentities($row[4])); print "

$body

\n"; if ($row[3] != "") { $safe = htmlentities($row[3]); $name = "$row[1]"; } else if ($row[2] != "") { $safe = addslashes($row[1]); $name = ""; } else { $name = htmlentities($row[1]); } printf("
Posted by %s on %s\n", $name, strftime("%e %B %Y %l:%M%p", $row[0])); print "
\n
\n"; $nocomment = 0; } /* Disconnect from the database */ mysql_close($link); print "
\n
\n"; ?>
Post a comment
Name:
E-mail:
URL:
Comment: