• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Custom user field with external (mysql table) verification

To give the user an additional string field, where it enters a certain key (for example AAA-BBB-CCC).
Check whether there is such key in the special table.
If there is no key, then it failed.
If the key is already used by someone, then it failed.
If the key is not used, then > write the user in this optional field the value of a specific field from a row that contains the value you entered.

Hereis the table itself:

Here is the my code:

class Myaddon_PaymentKey_Helper_UserField extends XenForo_Helper_UserField
    public static function verifyKey(array $field, &$value, &$error)
        $db = XenForo_Application::getDb();
        $get_search = $db->fetchAll("SELECT * FROM `xf_key_payments` WHERE `key_lic` LIKE '%$value%'");
        $get_type = $db->fetchOne("SELECT `type` FROM `xf_key_payments` WHERE `key_lic` LIKE '%$value%'");
        $get_id = $db->fetchOne("SELECT `ID` FROM `xf_key_payments` WHERE `key_lic` LIKE '%$value%'");
        $get_status = $db->fetchOne("SELECT `xf_user_id` FROM `xf_key_payments` WHERE `key_lic` LIKE '%$value%'");
        $visitor = XenForo_Visitor::getInstance();
        $userID = $visitor['user_id'];
        if ($get_search & $get_status == NULL)
            $value = $get_type;
        } else    {
            $error = new XenForo_Phrase('pg_invalid_key');
            return false;

        return array($db->query("UPDATE xf_key_payments SET xf_user_id = '$userID' WHERE ID = '$get_id'"));
And it works.
But I know that I did everything wrong. This is not optimal and besides not secure.

I'm not good at working with mysql, and because we got such a nonsense here. :)

Please help me in creating correct code.