Does someone know how to make this guestbook right?
He always posts the same date/hour/... for each message !
He doesn't post the time when the message actually is sent.
Also, can someone say how to make the script right, so there are only 10 posts per page.
And it generates automatically a link to the next page, where the next 10 messages are posted?
Some parts of the code are in Dutch so here are some translations:
naam = name
bericht = message
rij = row
gastenboek = guestbook
toegevoegd = added
verbinding = connection
This is the form:
PHP Code:
<form action="gbscript.php" method="post" >
<br>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
From: <input name="naam" maxlength="50">
<input name="datum" value="<?php echo date("d-m-Y H:i:s", time()); ?>" type="hidden">
</td>
</tr>
<tr>
<td>
E-mail: <input name="email" maxlength="50">
</td>
</tr><tr>
<td>
Website: <input name="website" maxlength="50">
</td>
</tr>
<tr>
<td>
<textarea name="bericht" rows="3" cols="10" maxlength="600">Typ hier uw bericht!</textarea><br>
<input type="submit" name="submit" value="Bericht plaatsen!">
</td>
</tr>
</table>
</form>
gbscript.php:
PHP Code:
<?php
if(isset($_REQUEST['submit'])) {
if(strlen($_REQUEST['naam']) == 0)
{
echo "You forgot to fill in the name of the sender!<br>";
echo "<a href=\"gastenboek.php\">Click here to return</a><br><p>";
}
if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_REQUEST['email']))
{
echo "Incorrect e-mail adress of the sender!<br>";
echo "<a href=\"gastenboek.php\">Click here to return</a><br><p>";
}
$datum = $_REQUEST['datum'];
$bericht = $_REQUEST['bericht'];
$email = $_REQUEST['email'];
$website = $_REQUEST['website'];
$naam = $_REQUEST['naam'];
$bericht = str_replace("\n", "<br>", $bericht);
$sql = "INSERT INTO `gastenboek` ";
$sql .= "(naam, email, website, bericht, datum) ";
$sql .= "VALUES ";
$sql .= "('$naam', '$email', '$website', '$bericht', '$datum') ";
$sql .= "; ";
require_once('mysql_connect.inc.php');
$verbinding = @mysql_connect(MYSQL_SERVER, MYSQL_GEBRUIKERSNAAM, MYSQL_WACHTWOORD) or die(mysql_error());
mysql_select_db("bulevardibase") or die(mysql_error());
$toegevoegd = mysql_query($sql) or die(mysql_error());
mysql_close($verbinding);
// to post the results of the guestbook:
if($toegevoegd) {
require_once('mysql_connect.inc.php');
$verbinding = @mysql_connect(MYSQL_SERVER, MYSQL_GEBRUIKERSNAAM, MYSQL_WACHTWOORD) or die(mysql_error());
mysql_select_db("bulevardibase") or die(mysql_error());
$sql = "SELECT * FROM gastenboek ORDER BY id DESC";
$tonen = mysql_query($sql) or die (mysql_error());
while ($rij = mysql_fetch_assoc($tonen)) {
$datum = $rij["datum"];
$naam = $rij["naam"];
$email = $rij["email"];
$website = $rij["website"];
$bericht = $rij["bericht"];
echo $datum ;
echo "<br>";
echo $naam ;
echo "<br>";
echo $website ;
echo "<br>";
echo $bericht ;
echo "<br><hr><br>";
}
mysql_free_result($tonen);
mysql_close($verbinding);
}
}
else {
echo "Please, fill in the form above!<p><br>";
}
?>