gpt4 book ai didi

php - 获取MySQL数据库中的IP地址

转载 作者:行者123 更新时间:2023-11-29 21:28:58 25 4
gpt4 key购买 nike

我尝试创建一个数据库来存储人们的 IP 地址,因此同一个 IP 地址不能订阅两次。我已经知道如何获取某人的 IP 地址,但我不知道如何将其插入我的数据库。这是我的代码:

 // Connect to MySQL
$mysqli = new mysqli( '***', '***', '***', 'inschrijven' );

// Check our connection
if ( $mysqli->connect_error ) {
die( 'Kan niet verbinden met database. Probeer het later opnieuw. ' . $mysqli->connect_errno . ': ' . $mysqli->connect_error );
}

// Insert our data

$sql = "INSERT INTO inschrijven ( naam, email, aantal,ip) VALUES ( '{$mysqli->real_escape_string($_POST['naam'])}', '{$mysqli->real_escape_string($_POST['email'])}', '{$mysqli->real_escape_string($_POST['aantal'])}'";
// validate agree unless you want to add 'checked' to one of the values

$insert = $mysqli->query($sql);


// Print response from MySQL
if ( $insert ) {
echo "U bent succesvol ingeschreven! U heeft bootnummer: {$mysqli->insert_id}. Op de naam: . U krijgt hiervan nog een bevesteging op uw mail, uw bootnummer kan nog veranderen. Hopelijk zien we u op de BotenBouwDag 2016!";
} else {
die("Error: {$mysqli->errno} : {$mysqli->error}");
}


$mysqli->close();
}

?>


<HTML>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

<title>
Welkom op de officiële site van de BotenBouwDag 2016
</title>
</head>
<body>

<form method="post" action="">
<input name="naam" id="naam" type="text">
<input name="email" id="email" type="email" autocomplete="off">
<input name="aantal" id="aantal" type="number">
<input type="radio" name="eten"> Ja
<input type="radio" name="eten"> Nee
<input type="submit" id="submit" value="Verstuur Informatie">
</form>

<div id="ip"></div>
<div id="address"></div>
<script type="text/javascript">

$.get("http://ipinfo.io", function (response) {
$("#ip").html("IP: " + response.ip);



document.getElementById('city').value = response.city;
}, "jsonp");
</script>


</body>
</HTML>

最佳答案

如果我猜对了。你应该将其添加到你的值(value)部分

VALUES ( '{$mysqli->real_escape_string($_POST['naam'])}', '{$mysqli->real_escape_string($_POST['email'])}', '{$mysqli->real_escape_string($_POST['aantal'])}','{$mysqli->real_escape_string($_SERVER['REMOTE_ADDR'])}'

关于php - 获取MySQL数据库中的IP地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35379975/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com