Jragon Posted July 6, 2010 Share Posted July 6, 2010 Hello I'm getting an error Error: Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\Sliqer.php on line 29 Code: <?php //Start Configeration //database host address $host = 'localhost'; //username to the database $user = 'root'; //database password $pass = ''; //database name $dbname - 'iplog'; //table to be used $tbname = 'logged_ips'; //End Configeration //finds out ip $ip = $_SERVER['REMOTE_ADDR']; //conects to the mysql server $connection = mysqli_connect($host, $user, $pass); //looks for duplacute ips $dup = mysqli_query($connection, 'SELECT * FROM `logged_ips`'); //checks to see if there is a duplecate name while($row = mysqli_fetch_assoc($dup)) { $ip_address = $row['Address_IP']; $visits = $row['Address_Visits'] +1; } if($ip_address != $_SERVER['REMOTE_ADDR']){ //inserts the ip in to the database $query = 'INSERT INTO `' . $dbname . '` (`Address_ID`, `Address_IP`, `Address_visits`); VALUES (\'0\', \'' . $ip . '\', \'1\');'; mysqli_query($connection, $query); }else{ //adds a visit to the database $query = "UPDATE `logged_ips` SET `Address_visits` = '++1' WHERE `ip_address` = $ip LIMIT 0,1"; mysqli_query($connection, $query); } //echos the ip echo $ip; ?> Thanks Jragon Quote Link to comment https://forums.phpfreaks.com/topic/206900-mysqli_fetch_assoc-error/ Share on other sites More sharing options...
Mchl Posted July 6, 2010 Share Posted July 6, 2010 This indicates your query failed for some reason. Use mysqli::error to find out why <?php if(!$dup = mysqli_query($connection, 'SELECT * FROM `logged_ips`')) { echo "Query error: ".$connection->error; die(); //stops script execution, for debugging purposes only - put proper error handling here } Quote Link to comment https://forums.phpfreaks.com/topic/206900-mysqli_fetch_assoc-error/#findComment-1082100 Share on other sites More sharing options...
Jragon Posted July 7, 2010 Author Share Posted July 7, 2010 Where should i put that codE? Quote Link to comment https://forums.phpfreaks.com/topic/206900-mysqli_fetch_assoc-error/#findComment-1082288 Share on other sites More sharing options...
Mchl Posted July 7, 2010 Share Posted July 7, 2010 Instead of $dup = mysqli_query($connection, 'SELECT * FROM `logged_ips`'); Quote Link to comment https://forums.phpfreaks.com/topic/206900-mysqli_fetch_assoc-error/#findComment-1082291 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.