Jump to content

Fatal error: Call to a member function fetch_object() on a non-object in C:\xamp


Danny620

Recommended Posts

When i run the script i get "Fatal error: Call to a member function fetch_object() on a non-object in C:\xampp\htdocs\tracker.php on line 23" however it does put data into the database.

 

<?php

class Tracker {

var $ip_address;
var $time;

function Logger($ip_address){

require 'mysqli.php'; 

$ip = $mysqli->real_escape_string($ip_address);

$time = date("m/d/y",time());

echo $ip;
echo "<br /> $time";

$query = "INSERT INTO tracker (ip, time) VALUES ('$ip', '$time')";  

$result = $mysqli->query($query) or die(mysqli_error($mysqli));

$row = $result->fetch_object();
  		
  		
  	}

}

$Tracker = new Tracker();

$ip = '82.0.154.172';//$_SERVER['REMOTE_ADDR'];

$Tracker->Logger($ip);

?>

Link to comment
Share on other sites

$result = $mysqli->query($query) or die(mysqli_error($mysqli));

 

$mysqli->query only returns an object for select (and show, describe, or explain) statements. Everything works fine until here:

 

$row = $result->fetch_object();

 

The query was an insert, so $result isn't an object, thus, call to a member function on a non-object.

Link to comment
Share on other sites

Field  Type  Collation  Attributes  Null  Default  Extra  Action

ip int(5) No None Browse distinct values Change Drop Primary Unique Index Fulltext

time int(11) No None Browse distinct values Change Drop Primary Unique Index Fulltext

Link to comment
Share on other sites

Since IP is not defined as a string, you're going to have trouble putting '82.0.154.172' into that column. =)

 

Also, your time is getting formatted as month/day/year

 

$time = date("m/d/y",time());

 

But the column is looking for a unix timestamp: time().

Link to comment
Share on other sites

IP's can't be stored as ints. You should change the column definition. It appears that the IP is used as part of a primary key, so I would suggest setting the column as a char(15).

 

As for the time, if you know how to use unix timestamps, use time(); instead of date("m/d/y", time());.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.