0
<?

$nick = $_POST['nick'];
$link = $_POST['link'];
$regiment = $_POST['regiment'];
$message = $_POST['message'];
$date = date('Y-m-d H:i:s');
$ip = $_SERVER['REMOTE_ADDR'];
$servername="localhost";
$username="pp";
$conn=  mysql_connect($servername,$username, mygas13)or die(mysql_error());
mysql_select_db("pp",$conn);

$ip = mysql_real_escape_string($_SERVER['REMOTE_ADDR']);


$sql = "SELECT TIMEDIFF(NOW(), `LastPost`) AS 'TimeSinceLast'
        FROM   `userTable`
        WHERE  `ip` = '{$ip}'
        AND    `LastPost` > DATE_SUB(NOW(), INTERVAL  1 DAY)";
$result = mysql_query($sql) or die(mysql_error());

if(mysql_num_rows($result) > 0) {

    $row = mysql_fetch_assoc($result);
    $timeSinceLast = date("G\h i\m s\s", strtotime($row['TimeSinceLast']));
$sql="insert into userTable (nick,link,message,regiment,ip,date,submitted) VALUES ('$nick', '$link', '$message', '$regiment', '$ip', '$date', 'Yes') ";

    $result=mysql_query($sql,$conn) or die(mysql_error());  

    }
else {
$servername="localhost";
$username="pp";
$conn=  mysql_connect($servername,$username, mygas13)or die(mysql_error());
mysql_select_db("pp",$conn);
$sql="insert into userTable (nick,link,message,regiment,ip,date,submitted) VALUES ('$nick', '$link', '$message', '$regiment', '$ip', '$date', 'No')";

$result=mysql_query($sql,$conn) or die(mysql_error());          

mysql_close($connection);

}
header("Location: thanks.html");
?>

这是我的 input.php。它提交数据,但它还会检查是否在 1 天内多次提交来自一个 ip。我不能做的是用是更新他/她提交的其余提交的值。我试过 DUPLICATE KEY UPDATE 但它没有用

4

0 回答 0