Hello,
The following code is supposed to stop a user from spamming form entries… only its not working.
Can anyone lend me a hand?
<?php
if ( isset($_POST['submit']) ) {
require_once('config.php');
$connect = mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($database);
$country = check_input($_POST['country'], "Please choose a country.");
$compname = check_input($_POST['companyname'], "Please enter your company's name.");
$email = htmlspecialchars($_POST['email']);
if (! preg_match("/([w-]+@[w-]+.[w-]+)/", $email) ) {
show_error('E-mail address not valid.');
}
$subject = check_input($_POST['subject'], "Please enter a subject.");
$message = check_input($_POST['message'], "Please enter your advertisement.");
$ip = $_SERVER['REMOTE_ADDR'];
$timeout = 20;
$result = mysql_query("SELECT submission_date FROM $table WHERE ip_address = '$ip' ORDER BY submission_date DESC LIMIT 1") or die('Error');
if(mysql_num_rows($result) == 1){
$info = mysql_fetch_array($result);
if(time() - $info['submission_date'] > $timeout * 60)
$insert = mysql_query("INSERT INTO $table (col_1, col_2, col_3, col_4, col_5, submission_date, ip_address) VALUES ('$country', '$compname', '$email', '$subject', '$message', ".time().", '$ip')");
else
die("Please submit no more than once per day.");
}
?>