Pointshop | MySQL

Hello! I am editing the pointshop side of MySQL, all I want to do is change a variable in my database everytime something updates.


function PROVIDER:SetPoints(ply, points)
    local qs = [[
    INSERT INTO `pointshop_data` (uniqueid, points, items, name)
    VALUES ('%s', '%s', '[]', '%s')
    ON DUPLICATE KEY UPDATE 
        points = VALUES(points)
    ]]
    qs = string.format(qs, ply:UniqueID(), points or 0)
    local q = db:query(qs)
     
    function q:onError(err, sql)
        if db:status() ~= mysqloo.DATABASE_CONNECTED then
            db:connect()
            db:wait()
        if db:status() ~= mysqloo.DATABASE_CONNECTED then
            ErrorNoHalt("Re-connection to database server failed.")
            return
            end
        end
        MsgN('PointShop MySQL: Query Failed: ' .. err .. ' (' .. sql .. ')')
        q:start()
    end
     
    q:start()
end

function PROVIDER:GivePoints(ply, points)
    local qs = [[
    INSERT INTO `pointshop_data` (uniqueid, points, items, name)
    VALUES ('%s', '%s', '[]', '%s')
    ON DUPLICATE KEY UPDATE 
        points = points + VALUES(points)
    ]]
    qs = string.format(qs, ply:UniqueID(), points or 0)
    local q = db:query(qs)
     
    function q:onError(err, sql)
        if db:status() ~= mysqloo.DATABASE_CONNECTED then
            db:connect()
            db:wait()
        if db:status() ~= mysqloo.DATABASE_CONNECTED then
            ErrorNoHalt("Re-connection to database server failed.")
            return
            end
        end
        MsgN('PointShop MySQL: Query Failed: ' .. err .. ' (' .. sql .. ')')
        q:start()
    end
     
    q:start()
end

function PROVIDER:TakePoints(ply, points)
    local qs = [[
    INSERT INTO `pointshop_data` (uniqueid, points, items, name)
    VALUES ('%s', '%s', '[]', '%s')
    ON DUPLICATE KEY UPDATE 
        points = points - VALUES(points)
    ]]
    qs = string.format(qs, ply:UniqueID(), points or 0)
    local q = db:query(qs)
     
    function q:onError(err, sql)
        if db:status() ~= mysqloo.DATABASE_CONNECTED then
            db:connect()
            db:wait()
        if db:status() ~= mysqloo.DATABASE_CONNECTED then
            ErrorNoHalt("Re-connection to database server failed.")
            return
            end
        end
        MsgN('PointShop MySQL: Query Failed: ' .. err .. ' (' .. sql .. ')')
        q:start()
    end
     
    q:start()
end

function PROVIDER:SaveItem(ply, item_id, data)
    self:GiveItem(ply, item_id, data)
end

function PROVIDER:GiveItem(ply, item_id, data)
    local tmp = table.Copy(ply.PS_Items)
    tmp[item_id] = data

    local qs = [[
    INSERT INTO `pointshop_data` (uniqueid, points, items, name)
    VALUES ('%s', '0', '%s', '%s')
    ON DUPLICATE KEY UPDATE 
        items = VALUES(items)
    ]]
    qs = string.format(qs, ply:UniqueID(), db:escape(util.TableToJSON(tmp)))
    local q = db:query(qs)
     
    function q:onError(err, sql)
        if db:status() ~= mysqloo.DATABASE_CONNECTED then
            db:connect()
            db:wait()
        if db:status() ~= mysqloo.DATABASE_CONNECTED then
            ErrorNoHalt("Re-connection to database server failed.")
            return
            end
        end
        MsgN('PointShop MySQL: Query Failed: ' .. err .. ' (' .. sql .. ')')
        q:start()
    end
     
    q:start()
end

function PROVIDER:TakeItem(ply, item_id)
    local tmp = table.Copy(ply.PS_Items)
    tmp[item_id] = nil

    local qs = [[
    INSERT INTO `pointshop_data` (uniqueid, points, items, name)
    VALUES ('%s', '0', '%s', '%s')
    ON DUPLICATE KEY UPDATE 
        items = VALUES(items)
    ]]
    qs = string.format(qs, ply:UniqueID(), db:escape(util.TableToJSON(tmp)))
    local q = db:query(qs)
     
    function q:onError(err, sql)
        if db:status() ~= mysqloo.DATABASE_CONNECTED then
            db:connect()
            db:wait()
        if db:status() ~= mysqloo.DATABASE_CONNECTED then
            ErrorNoHalt("Re-connection to database server failed.")
            return
            end
        end
        MsgN('PointShop MySQL: Query Failed: ' .. err .. ' (' .. sql .. ')')
        q:start()
    end
     
    q:start()
end
 
function PROVIDER:SetData(ply, points, items)
    local qs = [[
    INSERT INTO `pointshop_data` (uniqueid, points, items, name)
    VALUES ('%s', '%s', '%s', '%s')
    ON DUPLICATE KEY UPDATE 
        points = VALUES(points),
        items = VALUES(items)
    ]]
    qs = string.format(qs, ply:UniqueID(), points or 0, db:escape(util.TableToJSON(items)))
    local q = db:query(qs)
     
    function q:onError(err, sql)
        if db:status() ~= mysqloo.DATABASE_CONNECTED then
            db:connect()
            db:wait()
        if db:status() ~= mysqloo.DATABASE_CONNECTED then
            ErrorNoHalt("Re-connection to database server failed.")
            return
            end
        end
        MsgN('PointShop MySQL: Query Failed: ' .. err .. ' (' .. sql .. ')')
        q:start()
    end
     
    q:start()
end

The variable is called name, all I want to do is update the table players name every time they do it (as the uniqueid cannot be rendered into a steam name).
I have tried putting name = ply:Nick(), I have tried adding ply:Nick() at the end of the formatting… no luck?

Anyone know how I can just insert nick every time they get points etc…
(this is where I’m reading this)
http://ausweb1.streamline-servers.com/~australi/players.php

[editline]2nd September 2017[/editline]

(this value never updates, no matter what, oh and I manually added “Jacob” through PhpMyAdmin)

[editline]2nd September 2017[/editline]

And I was thinking of running this;


UPDATE `pointshop_data` SET `name` = ply:Nick() WHERE `pointshop_data`.`uniqueid` = ply:UniqueID();

But I have no idea where to put this ^ and how to run it.
(If the above cannot be changed)

If anyone can tell me how this works, or how to make this custom for myself, I would appreciate it.

[editline]3rd September 2017[/editline]

(by custom I mean how to create my own mysql editor in lua)