SOMEGUY SOMEGUY - 4 years ago 73
PHP Question

How would i get ip and insert the info in database

How would really get the ip and insert the data into the database i think this would be really simple but i cannot figure the syntax out for the code there has got to be something out there that can help me with my problem all answers would be appreciated.

Answer Source

Try this code:

<?php
$db_host = "localhost";
$db_user = "root";
$db_pass = "";
$db_name = "ip_cap";
$db = mysqli_connect($db_host, $db_user, $db_pass, $db_name);

if(mysqli_connect_errno()) {
die("Database connection failed: " . 
     mysqli_connect_error() . 
     " (" . mysqli_connect_errno() . ")"
);
}

$ip = $_SERVER['REMOTE_ADDR'];

$query  = "INSERT INTO ip_save (";
$query .= " ip";
$query .= ") VALUES (";
$query .= " '{$ip}'";
$query .= ")";
$result = mysqli_query($db, $query);
if(!$result) {
    die("database query failed");
}


?>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download