SaveCharacter()
var/DBConnection/dbcon = new()
var/connected = dbcon.Connect(DBI,username,server_pass)
if(!connected){alert(usr,"Connection failed: [dbcon.ErrorMsg()]");return}
var/Values={"
x=[usr.x],y=[usr.y],z=[usr.z],level=[usr.level],exp=[usr.exp],hp=[usr.hp],max_hp=[usr.max_hp],energy=[usr.energy],
max_energy=[usr.max_energy],atk=[usr.atk],def=[usr.def],spd=[usr.spd],money=[usr.money],baseicon=[usr.baseicon],
hairicon=[usr.hairicon],haircolor=[usr.haircolor]"}
var/query_sql ="SELECT * FROM `[my_database]`.`characters` WHERE `char_id` = '[usr.Char_ID]'"
var/insert_query="[query_sql] INSERT INTO `characters` SET '[Values]'"
var/update_query="UPDATE `characters` SET [Values] WHERE `char_id` = [usr.Char_ID]"
var/DBQuery/query = dbcon.NewQuery(query_sql)
if(!usr.Char_ID)
query_sql=insert_query
if(usr.Char_ID)
query_sql=update_query
query.Execute()
if(!query.Execute()){alert(usr,"Saving has failed.\n[query.ErrorMsg()]");return}
alert(usr,"You have successfully saved your character.")
query.Close()
dbcon.Disconnect()
Using Dantom.DB.
Problem description:I'm prob doing alot of things wrong, i can get the character to load if i put stuff in manual into the tables but i can't get it to save/update or even to create i've tried multiple ways, it reads the IDs from tables and everything but it wont save.
At a quick glance, it's probably because you're not encasing your variable values in anything, which is not valid SQL syntax.
Removing the excessive Execute() call should allow the query.ErrorMsg() part to output if there is in fact an error.