3 posts by 2 authors in: Forums > CMS Builder
Last Post: March 26   (RSS)

Hi All,

When using the website membership plugin v1.10 and previous, I’ve been using some custom code (suggested by Ross many moons ago) to write an entry into a login_log table every time a non-admin logged in. It was inserted into the plugin as in the code below.

With plugin V1.13 and PHP 7.2 the code no longer works (although I do get logged in, which I would expect the ‘or die’ code to have prevented) and I occasionally get the following error in the error log: UNCAUGHT_EXCEPTION: Call to undefined function mysql_query() /home3/mrqsygmy/public_html/cmsAdmin/plugins/websiteMembership_1.13_custom/websiteMembership_1.13_custom.php (line 230)
http://dbtproviders.com/provider_login.php

I think it has something to do with needing to update to mysqli, but I don’t really have a clue where to begin with something like this.

Any thoughts?

Thanks,

Jerry Kornbluth

// clear form values
$_REQUEST['username'] = '';
$_REQUEST['password'] = '';

// CUSTOM CODE! add record to login_log table


if (!@$CURRENT_USER['isAdmin'])
{global $TABLE_PREFIX;
mysql_query(mysql_escapef("INSERT INTO {$TABLE_PREFIX}login_log SET
createdDate = NOW(), // line 230
who = ?,
last_name = ?,
first_name = ?,
practice_name = ?",
$CURRENT_USER['num'],
$CURRENT_USER['num'],
$CURRENT_USER['num'],
$CURRENT_USER['num']))
or die("Mysql error adding login_log record: ". htmlspecialchars(mysql_error()) . "\n");
}
// redirect on success
$postLoginUrl = coalesce( getPrefixedCookie('lastUrl'), @$GLOBALS['WEBSITE_LOGIN_POST_LOGIN_URL'], '/' );
removePrefixedCookie('lastUrl');​
The first CMS Builder reference book is now available on-line!
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Hi Jerry,

To update mysql_query() for PHP 7, you can replace it with mysqli()->query(), like this:

mysqli()->query(mysql_escapef("INSERT INTO {$TABLE_PREFIX}login_log SET...

It's likely that there are library functions better suited to this action (such as mysql_insert()), but without requiring any big modifications, the above should at least fix the error.

Also, in the future, if you suspect you're having an issue with old MySQL functions, I'd recommend checking the Legacy MySQL Scanner plugin, which can be found in any recent CMSB installation (v3.12 or later). This should let you know if that's indeed the case, and also give some idea about what needs to be replaced if it's something custom like this.

Let me know if that takes care of the issue!

Thanks,

Daniel
PHP Programmer
interactivetools.com