1

Am trying to get every machines ip address and insert into a database on my website but for some reason am getting the following errors:

Warning: mysqli_stmt_bind_param(): invalid object or resource mysqli_stmt...

Warning: mysqli_stmt_execute(): invalid object or resource mysqli_stmt...

Warning: mysqli_stmt_store_result(): invalid object or resource mysqli_stmt...

Warning: mysqli_stmt_num_rows(): invalid object or resource mysqli_stmt...

Warning: mysqli_stmt_execute(): invalid object or resource mysqli_stmt in..

Warning: mysqli_stmt_execute(): invalid object or resource mysqli_stmt in...

And this is my code:

<?php
$deviceip=$_SERVER['REMOTE_ADDR'];
//check if ip is already in database
if(isset($deviceip)){
    $sql = "SELECT * FROM users WHERE deviceip=?";
    $resstmt = mysqli_stmt_init($db);
    mysqli_stmt_bind_param($resstmt,"s",$deviceip);
    mysqli_stmt_execute($resstmt);
    //did we get a match?
    mysqli_stmt_store_result($resstmt);
    $resultCheck = mysqli_stmt_num_rows($resstmt);
    if($resultCheck ==0){
        $sql = "INSERT INTO deviceips(deviceip) VALUES (?)";
        $resstmt = mysqli_stmt_init($db);
        mysqli_stmt_prepare($resstmt,$sql);
        mysqli_stmt_bind_param($resstmt,"s",$deviceip);;
        mysqli_stmt_execute($resstmt);
    }
}?>
Elly Nw
  • 7
  • 6

1 Answers1

0

As you are getting so many errors, I'd suppose there is no connection to the database. If you have posted all your code, then you maybe missed to establish a connection. Try these lines before your queries:

$db = mysqli_connect(SERVER_DNS_OR_IP, DATABASE_USER, USER_PASSWORD, DATABASE_NAME); if(mysqli_connect_errno()) { ... do some error handling... }

Replace the capitalized data with your own database data.