Virtue 10 Posted April 24, 2014 I know we have a command to get the account id, i have a question though, if in any case i want to store a username, i'll have to use getcharid(3) right? so how will i query it?so that it gets save in the sql as the username not the account id. Quote Share this post Link to post Share on other sites
0 jaBote 438 Posted April 24, 2014 getcharid(3) returns Account ID of the user (source doc). Maybe you meant strcharinfo(0), which returns current character's name (source doc). You could do something like this on your SQL: .@name$ = strcharinfo(0);.@sql$ = "INSERT INTO `my_table` VALUES ('" + .@name$ + "')";query_sql(.@sql$); Or, all in one sentence: query_sql("INSERT INTO `my_table` VALUES ('" + strcharinfo(0) + "')"); Quote Share this post Link to post Share on other sites
0 Virtue 10 Posted April 24, 2014 (edited) yes i've checked the script_docs but to no avail, and from using the getcharid(3), I believe we can use some query to get the username not char name/id. query_sql("SELECT `login` VALUES ('" + getcharid(3) + "') ______ userid im thinking something like that but i can't seem to remember what command is needed so that when you do the query you'll get the values for the userid. Edited April 24, 2014 by Virtue Quote Share this post Link to post Share on other sites
0 Virtue 10 Posted April 24, 2014 or maybe it would be something like query_sql("SELECT userid FROM `login` then after I'm not sure what will come next so its like, select the userid from login database using the account_id(getcharid(3)) Quote Share this post Link to post Share on other sites
0 jaBote 438 Posted April 24, 2014 If you want to retrieve the name of the current character via SQL, then this is what you should do: query_sql("SELECT `name` FROM `char` WHERE `account_id` = " + getcharid(3) + " AND `online` = 1",.@name$); Missing the online condition will lead you to retrieve all characters for that account instead of just the character's name. But you could use getcharid(0) (retrieves user's char ID) and use next SQL query: query_sql("SELECT `name` FROM `char` WHERE `char_id` = " + getcharid(0),.@name$); Which will guarantee you'll get your username from the SQL table. Quote Share this post Link to post Share on other sites
0 Virtue 10 Posted April 24, 2014 haha i think im having an idea of what i have to do, although im not yet a hundred percent sure, although i meant username/userid but hey, thanks so if im correct the query should be query_sql("SELECT `userid` FROM `login` WHERE `account_id` = " + getcharid(3),.@username$); Quote Share this post Link to post Share on other sites
0 jaBote 438 Posted April 24, 2014 I don't get you. You want to get username AND userID from the database, given you've got just the account ID, without making use of the commands you're given to get them directly? If not, please elaborate. P.S.: looks like you want to reinvent the wheel xD Quote Share this post Link to post Share on other sites
0 Virtue 10 Posted April 24, 2014 nope, i don't want to get the username and userid. haha. i just used the term username/id bec. they're just the same. query_sql("SELECT `name` FROM `char` WHERE `char_id` = " + getcharid(0),.@name$); this one gets the name of the character right? what i am looking for would be the userid, the one that we use to login, Quote Share this post Link to post Share on other sites
0 Dastgir 1246 Posted April 24, 2014 query_sql("SELECT `userid` FROM `login` WHERE `account_id` = " + getcharid(3),.@username$); This returns UserName of the Account nope, i don't want to get the username and userid. haha. i just used the term username/id bec. they're just the same. query_sql("SELECT `name` FROM `char` WHERE `char_id` = " + getcharid(0),.@name$); this one gets the name of the character right? what i am looking for would be the userid, the one that we use to login, Why use a query to get Character name, you can get character name by "strcharinfo(0)" Quote Share this post Link to post Share on other sites
0 jaBote 438 Posted April 24, 2014 nope, i don't want to get the username and userid. haha. i just used the term username/id bec. they're just the same. query_sql("SELECT `name` FROM `char` WHERE `char_id` = " + getcharid(0),.@name$); this one gets the name of the character right? what i am looking for would be the userid, the one that we use to login, Account name? Then it's like this: query_sql("SELECT `userid` FROM `login` WHERE `account_id` = " + getcharid(3)),.@userid$; Quote Share this post Link to post Share on other sites
0 Virtue 10 Posted April 24, 2014 yep. thanks to the both of you, Quote Share this post Link to post Share on other sites
0 Virtue 10 Posted April 25, 2014 (edited) query_sql("SELECT `userid` FROM `login` WHERE `account_id` = " + getcharid(3),.@username$);This returns UserName of the Account nope, i don't want to get the username and userid. haha. i just used the term username/id bec. they're just the same. query_sql("SELECT `name` FROM `char` WHERE `char_id` = " + getcharid(0),.@name$);this one gets the name of the character right? what i am looking for would be the userid, the one that we use to login, Why use a query to get Character name, you can get character name by "strcharinfo(0)" follow up question on this one, input @input$;query_sql("SELECT `userid` FROM `login` WHERE `userid` = " + @input$,.@username$);if the query did not return any value/result. should this script work like this if(@input$ == .@username$){dispbottom "Value Found";}dispbottom "No Results";hypothetically its just a sample but it should be working right?if the input has the same value or correct value from the db it should give me "value found" if the username that i entered is correct. Edited April 25, 2014 by Virtue Quote Share this post Link to post Share on other sites
0 Dastgir 1246 Posted April 25, 2014 query_sql("SELECT `userid` FROM `login` WHERE `account_id` = " + getcharid(3),.@username$);This returns UserName of the Account nope, i don't want to get the username and userid. haha. i just used the term username/id bec. they're just the same. query_sql("SELECT `name` FROM `char` WHERE `char_id` = " + getcharid(0),.@name$);this one gets the name of the character right? what i am looking for would be the userid, the one that we use to login, Why use a query to get Character name, you can get character name by "strcharinfo(0)" follow up question on this one, input @input$;query_sql("SELECT `userid` FROM `login` WHERE `userid` = " + @input$,.@username$);if the query did not return any value/result. should this script work like this if(@input$ == .@username$){dispbottom "Value Found";}dispbottom "No Results";hypothetically its just a sample but it should be working right?if the input has the same value or correct value from the db it should give me "value found" if the username that i entered is correct. If the input userid exists in login table, then it will display "Value Found" Else it will display "No Results but you forgot the else statement, if(@input$ == .@username$){ dispbottom "Value Found";} else { dispbottom "No Results";} Quote Share this post Link to post Share on other sites
0 Virtue 10 Posted April 25, 2014 o yeah, sorry. but basically what i'm thinking of is quite possible, been away for so long got super rusty that's why need to check esp when using sql queries with scripts. Quote Share this post Link to post Share on other sites
I know we have a command to get the account id, i have a question though,
if in any case i want to store a username, i'll have to use getcharid(3) right? so how will i query it?so that it gets save in the sql as the username not the account id.
Share this post
Link to post
Share on other sites