Danny620 Posted April 1, 2010 Share Posted April 1, 2010 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); ?> Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 1, 2010 Share Posted April 1, 2010 INSERT queries don't return result sets. There is nothing to fetch after an INSERT query. Why are you trying to use - $row = $result->fetch_object(); Quote Link to comment Share on other sites More sharing options...
ialsoagree Posted April 1, 2010 Share Posted April 1, 2010 $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. Quote Link to comment Share on other sites More sharing options...
Danny620 Posted April 1, 2010 Author Share Posted April 1, 2010 lol why did'tn i think of that sorry for wasting your time. 1 more thing it only inserts 820 into the db for the ip and 4 for the time. why is this? Quote Link to comment Share on other sites More sharing options...
ialsoagree Posted April 1, 2010 Share Posted April 1, 2010 If it was a waste of time, we wouldn't be here answering questions, so no worries. The first thing that comes to mind, what are the database column definitions? Quote Link to comment Share on other sites More sharing options...
Danny620 Posted April 1, 2010 Author Share Posted April 1, 2010 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 Quote Link to comment Share on other sites More sharing options...
ialsoagree Posted April 1, 2010 Share Posted April 1, 2010 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(). Quote Link to comment Share on other sites More sharing options...
Danny620 Posted April 1, 2010 Author Share Posted April 1, 2010 what should i do then? Quote Link to comment Share on other sites More sharing options...
ialsoagree Posted April 1, 2010 Share Posted April 1, 2010 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());. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.