如何检查数据库中是否有IP?

时间:2014-01-16 18:07:26

标签: php sql

我想检查数据库中是否有IP,如果是,请让他们等待5分钟再重新发布...

$sqlip = "localhost";
$sqluser = "xxxxx";
$sqlpass = "xxxxxx";
$con = mysqli_connect($sqlip, $sqluser, $sqlpass, "keinettradio");

if(!$con){

    die("Failed to connect..") . mysqli_error();

}

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

$ipwrite = "INSERT INTO `iplogger`(`ip`, `time`) VALUES ('$ip', 'date(Y-m-d H:i:s)')";
$ipcheck = mysqli_query($con, $ipcheck2);
$ipcheck2 = "SELECT * FROM `iplogger` WHERE `ip` LIKE `$ip`";


if($ipcheck) {
    echo "True!";
} else {
    $ipwrite;
}

我刚刚开始编码,我没有人帮助我,所以我发现它很难。感谢。

1 个答案:

答案 0 :(得分:0)

你能试试吗,

    $sqlip = "localhost";
    $sqluser = "xxxxx";
    $sqlpass = "xxxxxx";
    $con = mysqli_connect($sqlip, $sqluser, $sqlpass, "keinettradio");      
    if(!$con){      
        die("Failed to connect..") . mysqli_error();        
    }       
    $ip = mysqli_real_escape_string($con, $_SERVER['REMOTE_ADDR']);     

    $ipcheck2 = "SELECT * FROM `iplogger` WHERE `ip` = '$ip' ";
    $ipcheckResult = mysqli_query($con, $ipcheck2);     
    $rowcount=mysqli_num_rows($ipcheckResult);      
    if($rowcount>0){
          echo "True! IP Exist";
    }else{
        echo "Insert IP address";
        $ipwrite = "INSERT INTO `iplogger` (`ip`, `time`) VALUES ('$ip', '".date('Y-m-d H:i:s')."')";
        $ipcheck = mysqli_query($con, $ipwrite);
    }