Scripts
Guestbook
LAST UPDATED: *10-10-2008* Smilies: Download (plaats deze vervolgens in ./smilies/) Allereerst moet je een database aanmaken met de naam 'guestbook' Dit database heeft de volgende instellingen: Hierna is alleen nog de code nodig en zou het gastenboek als goed is moeten werken! :) Enjoy!
guestbook
--------------- ./smilies/smilies.php ---------------
[code]<?php
$smiles = array(
':p'=>'tongue',
':?'=>'confused',
'8)'=>'cool',
':|'=>'sleepy',
':@'=>'mad',
':O'=>'surprised',
':d'=>'happy',
':)'=>'smile',
':D'=>'biggrin',
':('=>'cry',
':P'=>'drool');
foreach($smiles as $smile=>$image){
$comment = str_replace($smile,"<img src=./smilies/".$image.".gif>", $comment);
}
?>[/code]
--------------- Index.php ---------------
[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head><title>Guestbook</title></head>
<body bgcolor="#98AFC7">
<style type="text/css">
table {
border: 2px solid #00008B;
background-color: #e6e6e6;
}
h1 {
font-family: Tahoma;
}
td {
border: 1px solid blue;
font-size: 13px;
font-family: Tahoma;
}
th {
border: 1px solid blue;
font-size: 11px;
font-family: Tahoma;
}
textarea {
font-family: Tahoma;
font-size: 11px;
}
input {
font-family: Tahoma;
font-size: 11px;
}
p {
font-family: Tahoma;
font-size: 13px;
text-decoration: underline;
}
font {
font-family: Tahoma;
font-size: 12px;
}
</style>
<center>
<h1>Guestbook!</h1>
<?php
$mysqli = new mysqli("localhost","root","","guestbook");
$comment = ($_REQUEST["comment"]);
$hashed_comment = md5($comment);
$query = "SELECT count(ID) FROM messages";
$result = $mysqli->query($query);
$queryData = mysqli_fetch_row($result);
$numRows = $queryData[0];
$rowsPerPage = 10;
$pageNum = 1;
$lastPage = ceil($numRows / $rowsPerPage);
if(isset($_GET["page"])) {
$pageNum = $_GET["page"];
}
$offset = ($pageNum - 1) * $rowsPerPage;
$query = "SELECT * FROM `messages` WHERE `Unique` = '".$hashed_comment."'";
$rs = $mysqli->query($query);
if($rs->num_rows == 0) {
if(isset($_REQUEST["name"])) {
$name = trim(strip_tags($_REQUEST["name"]));
}
if(isset($_REQUEST["nobot"])) {
$nobot = trim(strip_tags($_REQUEST["nobot"]));
}
if(isset($_REQUEST["comment"])) {
$comment = nl2br(trim(strip_tags($_REQUEST["comment"])));
if(empty($name) || empty($comment) || !empty($nobot)) {
echo "<p>You have to fill in both fields in order to submit a post.</p>";
}
else {
include("./smilies/smilies.php");
$query = "INSERT INTO messages (`Name`, `Message`, `Unique`, `NoBot`) VALUES('".$mysqli->real_escape_string($name)."','".$mysqli->real_escape_string($comment)."','".$mysqli->real_escape_string($hashed_comment)."','".$mysqli->real_escape_string($nobot)."')";
$mysqli->query($query);
}
}
}
else {
echo "<p>Don't SPAM!</p>";
}
$query = "SELECT * FROM messages ORDER BY `Date` DESC LIMIT ".$offset.", ".$rowsPerPage."";
$rs = $mysqli->query($query);
while($row = $rs->fetch_array()) {
echo "<table><tr><td colspan=3>".wordwrap($row["Message"], 38, " ", " ")."</td></tr><tr><th width=200>".$row["Name"]."</th><th width=200>".$row["Date"]."</th><th width=50>#".$row["ID"]."</th></tr></table><br />";
}
$nextPage = $pageNum+1;
$prevPage = $pageNum-1;
if ($pageNum == 1) {
echo "<font> FIRST PREV </font>";
}
else {
echo " <a href=\"".$_SERVER['PHP_SELF']."?page=1\"><font>FIRST</font></a> ";
echo " <a href=\"".$_SERVER['PHP_SELF']."?page=".$prevPage."\"><font>PREV</font></a> ";
}
echo "<font> ( Page ".$pageNum." of ".$lastPage." ) </font>";
if ($pageNum == $lastPage) {
echo "<font> NEXT LAST </font>";
}
else {
echo " <a href=\"".$_SERVER['PHP_SELF']."?page=".$nextPage."\"><font>NEXT</font></a> ";
echo " <a href=\"".$_SERVER['PHP_SELF']."?page=".$lastPage."\"><font>LAST</font></a> ";
}
?>
<p>
<form name='Form1' method='post' action='index.php'>
<table>
<tr>
<th width='100'>
Name:
</th>
<td>
<input name='name' />
</td>
</tr>
<tr>
<th width='100'>
Message:
</th>
<td>
<textarea name='comment'></textarea>
<input type='hidden' name='nobot' />
</td>
</tr>
</table>
<br />
<input type='submit' value='Submit' />
</form>
</p>
</center>
</body>
</html>[/code]
Reacties
0