我正在努力做到这一点,如果他们的 IP 在数据库中,那么他们就无法发送电子邮件。在 php54_errors 文件中它说
[30-Dec-2012 18:25:26 Europe/Dublin] PHP Warning: mysql_num_rows() expects parameter 1 to be resource, string given in C:\inetpub\wwwroot\Submit.php on line 6
[30-Dec-2012 18:25:26 Europe/Dublin] PHP Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\inetpub\wwwroot\Submit.php on line 7
我的 PHP 代码是这样的
<?php
include("connect.php");
mysql_select_db("ip", $con);
$ip = mysql_real_escape_string($_SERVER['REMOTE_ADDR']);
$query = "SELECT * FROM ip WHERE ip='$ip'";
$result = mysql_num_rows($query);
if (mysql_num_rows($result) > 0) {
echo "You have already registered!";
}
else {
echo"Your request has been sent!";
$to = "admin@prisoneternity.org.uk";
$subject = "Guard Application";
$from = "guardapplication@prisoneternity.org.uk";
$headers = "From:" . $from;
$message = "IGN = " . $_POST["Username"] . "</br>\n\nage = " . $_POST["age"] . "</br>\n\nreason = " . $_POST["reason"] . "</br>\n\nHow many times have they been guard = " . $_POST["guard"] . "</br>\n\nOther Details = " . $_POST["text"];
mail($to,$subject,$message,$headers);
header ("Location: index.php?email=yes");
session_start();
mysql_query("INSERT INTO ip (IP) VALUES ('$ip')");
}
?>