ID:1127548
 
(See the best response by Pirion.)
Code:
client

proc
Save(mob/M)
for(var/V=1 to M.vars.len)
{
if(ignored_vars.Find(M.vars[V]))
{
continue
}
else
{
Query("UPDATE `[sql_table]` SET [V]='[M.vars[V]]' WHERE name='[M.name]';")
}
}
mb_msgout("Character saved.", M)


Problem description:

>.> what am i doing wrong.. inserting the variables works fine but not updating?

im using this library
http://www.byond.com/developer/DivineTraveller/ MySQLmobsaving
Maybe you can show us your insert code, and we can look at what you are doing differently?
Best response
Looking at forum post:
http://www.byond.com/forum/?post=1127261

It looks as though you have named fields, yet for(var/V=1 to M.vars.len) is looking though 1 2 3 4 5 (etc), and saving them as indexes.

I would assume you need to do for(var/x in M.vars) and M.vars[x] to get the name/value pair.

Try outputting your SQL statement to confirm this, and if so - fix.

Edit: You can also greatly reduce the SQL queries you run by combining them:

var/combineStatements = "";
var/loop = 0
for(var/V in M.vars)
{
if(!ignored_vars.Find(M.vars[V]))
{
if(loop>0)
{
combineStatements += ",";
loop++;
}
combineStatements += "[V]='[M.vars[V]]'";
}
}
var/query = "UPDATE `[sql_table]` SET [combineStatements] WHERE name='[M.name]';"
It is now saving but for some reason it is leaving out some variables that were not added to the ignore list.. i don't know why.

    SaveCharacter(mob/M)
var/combineStatements = "";
var/loop = 0
var/X = 1
for(var/V in M.vars)
{
if(isclient(M.vars[M.vars[X]]) || ignored_vars.Find(M.vars[X])) continue
if(loop>0)
{
combineStatements += ", ";
}
combineStatements += "[V]='[M.vars[V]]'";
loop++;
X++;
}
var/query = "UPDATE `[sql_table]` SET [combineStatements] WHERE name='[M.name]';"
world.log << query
return query


Never mind i got it all resolved thanks for the guidance.