Topic: Mod User Stats

Hello

I setup this mod User Stats

and I got this message

Il y aurait une erreur de syntaxe ds la requèete SQL ?

PunBB reported: Unable to insert into user statistics
Database reported: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.220.86)' at line 1 (Errno: 1064)

This is the code of the fonction within the pb

// MOD USERSTATS CHANGE
if ($pun_user['idle'] == 1)  {
$db->query('INSERT INTO '.$db->prefix.'statuser (user_id, user_ip) VALUES('.$pun_user['id'].',"'.$db->escape(get_remote_address()).'")') or error('Could not insert into statistics', __FILE__, __LINE__, $db->error());
}
// END MOD USERSTATS CHANGE

Re: Mod User Stats

Does any one know ?

Re: Mod User Stats

Yes, the IP is a string. Not a numeric value. So it should be in quotes.

Re: Mod User Stats

elbekko wrote:

Yes, the IP is a string. Not a numeric value. So it should be in quotes.

but it is already in quotes !!! no ?

"'.$db->escape(get_remote_address()).'"

I mean these quotes

"    '    .$db->escape(get_remote_address()).    '    "

??????

Re: Mod User Stats

Hrmm, so it is. Sorry, misread.

Could you post the structure of the table? (columns, types)

Re: Mod User Stats

forum_statuser

id int(11) auto_increment       
user_id int(11)    
logind timestamp ON UPDATE CURRENT_TIMESTAMP CURRENT_TIMESTAMP
user_ip varchar(15)

Re: Mod User Stats

You're not looking at the right query
Your error message "Unable to insert into user statistics"
That query's error message "Could not insert into statistics"

Re: Mod User Stats

Here is the Mod. Did you try it before ?

##
##
##        Mod title:  Userstats
##
##      Mod version:  1.0.1
##   Works on PunBB:  1.2.5
##     Release date:  2005-07-01
##           Author:  Tobi (tobi@tobi.gr)
##
##      Description:  This mod comes together with the Plugin AP_user_statistics and
##                    one does not make any sense without the other! 
##                    For your convenience the plugin file AP_user_statistics.php
##                    is included with this mod.
##                    It allows the Administrator to see statistics for: 
##                    - How many and which users visited in a certain period
##                    - Which topics they saw
##                    - The total number of visits per day for a given period
##                    - The most read topics for a given period
##
##   Affected files:  functions.php
##                    viewtopic.php
##
##       Affects DB:  Yes
##
##            Notes:  1. The install_mod routine currently works only for MySQL.
##                    2. The table YOURBOARDstatviews_all can become pretty big
##                       depending on how many registered users visit your board.
##                       It has to be cleaned up manually unless I decide to add 
##                       a routine for it (or somebody else does) ;-)
##                    3. As long as your statistics tables in the database are not filled
##                       with user entries you will of course receive some errors ;-)
##
##    Release Notes:  - Text Modifications in AP_USer_statistics.php
##                    - Nicer error messages when no matches are found to dismplay by the plugin 
##                    - Removed YOURBOARDstatviews_daily from the install_mod.php
##                      The routines behind it are not currently implemented.
##
##       DISCLAIMER:  Please note that "mods" are not officially supported by
##                    PunBB. Installation of this modification is done at your
##                    own risk. Backup your forum database and any and all
##                    applicable files before proceeding.
##
##

#
#---------[ 1. UPLOAD ]------------------------------------------------------
#

install_mod.php


#---------[ 2. RUN ]---------------------------------------------------
#

install_mod.php

#
#---------[ 3. DELETE ]---------------------------------------------------
#

install_mod.php

#
#---------[ 4. OPEN ]---------------------------------------------------
#
include/functions.php


#
#---------[ 5. FIND (line:76) ]---------------------------------------------------
#
            // Update the online list
            if (!$pun_user['logged'])
                $db->query('INSERT INTO '.$db->prefix.'online (user_id, ident, logged) VALUES('.$pun_user['id'].', \''.$db->escape($pun_user['username']).'\', '.$now.')') or error('Unable to insert into online list', __FILE__, __LINE__, $db->error());
                }

#
#---------[ 6. CHANGE TO ]---------------------------------------------------
#
            // Update the online list
// MOD USERSTATS CHANGE
            if (!$pun_user['logged'])  {
                $db->query('INSERT INTO '.$db->prefix.'online (user_id, ident, logged) VALUES('.$pun_user['id'].', \''.$db->escape($pun_user['username']).'\', '.$now.')') or error('Unable to insert into online list', __FILE__, __LINE__, $db->error());
                $db->query('INSERT INTO'.$db->prefix.'statuser (user_id, user_ip) VALUES('.$pun_user['id'].','.$db->escape(get_remote_address()).')') or error('Unable to insert into user statistics', __FILE__, __LINE__, $db->error());
                }
// END MOD USERSTATS CHANGE


#
#---------[ 7. FIND (line:92) ]---------------------------------------------------
#

$idle_sql = ($pun_user['idle'] == '1') ? ', idle=0' : '';


#
#---------[ 8. BEFORE, ADD ]---------------------------------------------------
#


// MOD USERSTATS CHANGE
            if ($pun_user['idle'] == 1)  {
                $db->query('INSERT INTO '.$db->prefix.'statuser (user_id, user_ip) VALUES('.$pun_user['id'].',"'.$db->escape(get_remote_address()).'")') or error('Could not insert into statistics', __FILE__, __LINE__, $db->error());
                }
// END MOD USERSTATS CHANGE


#
#---------[ 9. OPEN ]---------------------------------------------------
#
viewtopic.php


#
#---------[ 10. FIND (line:102) ]---------------------------------------------------
#
            if (!$db->num_rows($result))
    message($lang_common['Bad request']);
#
#---------[ 11. BEFORE, ADD ]---------------------------------------------------
#

// MOD USERSTATS
$statresult = $db->query('insert into '.$db->prefix.'statviews_all(user_id, topic_id) VALUES (' . $pun_user['id'] . ', '.$id.')') or error('Unable to update view statistics', __FILE__, __LINE__, $db->error());
// MOD USERSTATS

Re: Mod User Stats

Ill install this mod today or tomorrow and let you know how it goes for me. Sorry I can't be of more help.

Re: Mod User Stats

towelie wrote:

Ill install this mod today or tomorrow and let you know how it goes for me. Sorry I can't be of more help.

thanks :)))

Re: Mod User Stats

And here's the problem query (from step 6)

$db->query('INSERT INTO'.$db->prefix.'statuser (user_id, user_ip) VALUES('.$pun_user['id'].','.$db->escape(get_remote_address()).')') or error('Unable to insert into user statistics', __FILE__, __LINE__, $db->error());

should be

$db->query('INSERT INTO '.$db->prefix.'statuser (user_id, user_ip) VALUES('.$pun_user['id'].',"'.$db->escape(get_remote_address()).'")') or error('Unable to insert into user statistics', __FILE__, __LINE__, $db->error());

Re: Mod User Stats

Smartys wrote:

And here's the problem query (from step 6)

$db->query('INSERT INTO'.$db->prefix.'statuser (user_id, user_ip) VALUES('.$pun_user['id'].','.$db->escape(get_remote_address()).')') or error('Unable to insert into user statistics', __FILE__, __LINE__, $db->error());

should be

$db->query('INSERT INTO '.$db->prefix.'statuser (user_id, user_ip) VALUES('.$pun_user['id'].',"'.$db->escape(get_remote_address()).'")') or error('Unable to insert into user statistics', __FILE__, __LINE__, $db->error());

Thank you Smartys ! You saw what I could not :( ONE SPACE AND TWO QUOTES :P
:)))))