First off, i'm a php and mysql n00b trying to create an guestbook. My first problem is that the time shown in every post says 00:00:00, the date works.
Second problem is i'm trying to implement this CAPTCHA http://www.white-hat-web-design.co.uk/a ... aptcha.php with no problem getting the captcha-image and text-input to show, but can't get the code that will validate the text-input when clicking the submit button to work with my own code.
Any suggestions?
My single file guestbook without CAPTCHA:
Code: Select all
<?php
//connect to the database
$connect = mysql_connect ("my host","user","pass") or die("Error connecting to db");
//select table
mysql_select_db("my db") or die("Error selecting db");
echo "<head>
<link href='style.css' rel='stylesheet' type='text/css'>
</head>
<body leftmargin='20' topmargin='15'>
";
if ($_POST['submit'])
{
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$date = date("y-m-d");
$time = time("H:i:s");
if ($name&&$message)
{
$querypost = mysql_query("INSERT INTO guestbook VALUES ('','$name','$email','$message','$date','$time')");
echo "Please wait... <meta http-equiv='refresh' content='2'>";
}
else
echo "Please fill out both Name and Comment fields!";
}
echo "
<table width='100%'>
<tr>
<td class='borderTabell2'>
<form action='index.php' method='POST'>
<table width='100%' cellspacing='1' cellpadding='2'>
<tr>
<td width='25%'>
<font size='2'>Name:</font>
</td>
<td>
<input type='text' size='55' name='name' maxlength='50'>
</td>
</tr>
<tr>
<td>
<font size='2'>Email:</font>
</td>
<td>
<input type='text' size='55' name='email' maxlength='50'>
</td>
</tr>
<tr>
<td valign='top'>
<font size='2'>Comment:</font>
</td>
<td>
<textarea cols='40' rows='5' name='message' maxlength='250'></textarea>
</td>
</tr>
<tr>
<td>
</td>
<td align='center'>
<input type='submit' name='submit' value='Post'>
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
";
echo "<table border='0'>
<tr>
<td height='20'>
</td>
</tr>
</table>";
//use query to get ALL data
$queryget = mysql_query("SELECT * FROM guestbook ORDER BY `id` DESC") or die("Error with query");
while ($row = mysql_fetch_assoc($queryget))
{
//get row data and store in vars
$id = $row['id'];
$name = $row['name'];
$email = $row['email'];
$message = $row['message'];
$date = $row['date'];
$time = $row['time'];
// show data to user
echo"
<table width='100%'>
<tr>
<td class='borderTabell2'>
<table width='100%' cellspacing='1' cellpadding='2'>
<tr>
<td width='50%'>
<font size='1'><b>#$id</b></font>
</td>
<td width='50%' align='right'>
<font size='1'><b>$date $time</b></font>
</td>
</tr>
<tr>
<td colspan='2'>
<font size='1'><b>Name: $name </b></font>
</td>
</tr>
<tr>
<td colspan='2'>
<font size='2'> ".nl2br(strip_tags($message))." </font>
</td>
</tr>
</table>
</td>
</tr>
</table>
";
}
?>Code: Select all
<?php
session_start();
if( isset($_POST['submit'])) {
if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) {
// Insert you code for processing the form here, e.g emailing the submission, entering it into a database.
echo 'Thank you. Your message said "'.$_POST['message'].'"';
unset($_SESSION['security_code']);
} else {
// Insert your code for showing an error message here
echo 'Sorry, you have provided an invalid security code';
}
} else {
?>