Virtue Posted January 16, 2013 Posted January 16, 2013 Hi, I am making myself an SQL Script, now, how do i insert the character name to the sql_query? tried putting the exact name there but i got an error? INSERT INTO `points` (char_id,name,points) VALUES (150000,????,1) will it work if i made it like this query_sql (INSERT INTO `points` (char_id,name,points) VALUES (150000,strcharinfo(0),1)) Quote
KeyWorld Posted January 16, 2013 Posted January 16, 2013 First you have to put QUOTE. Second you have to secure the string entry. query_sql("INSERT INTO `points` ( `char_id`, `name`, `points`) VALUES ('150000', '" + escale_sql(strcharinfo(0)) + "', '1')"); 1 Quote
Virtue Posted January 16, 2013 Author Posted January 16, 2013 will try that thanks so assuming that there is no value at all would this be correct? query_sql("INSERT INTO `points` ( `char_id`, `name`, `points`) VALUES ('" + escale_sql(getcharid(0)) + "', '" + escale_sql(strcharinfo(0)) + "', '"+ .@points + "')"); Quote
KeyWorld Posted January 16, 2013 Posted January 16, 2013 Yeah it should. But you don't need escape_sql() on an INT variable just on string. 1 Quote
Virtue Posted January 16, 2013 Author Posted January 16, 2013 alright. so query_sql("INSERT INTO `points` ( `char_id`, `name`, `points`) VALUES ('" + getcharid(0) + "', '" + escale_sql(strcharinfo(0)) + "', '"+ .@points + "')"); then when updating the sql db it should be like this right query_sql("UPDATE points SET points = ( points + " + .@points + " ) WHERE char_id = "+getcharid(0); Quote
AnnieRuru Posted January 16, 2013 Posted January 16, 2013 meh only teach advance scripting techniques xD create table test_point ( char_id int(11) unsigned primary key, name varchar(24), points int(11), key (name) ) engine = innodb; prontera,155,182,4 script kjsdfksdjfhs 100,{ query_sql "select points from test_point where char_id = "+ getcharid(0), .@points; mes "you currently have "+ .@points +" points"; close; OnNPCKillEvent: if ( killedrid != 1002 ) end; .@points = rand(10); query_sql "insert into test_point values ( "+ getcharid(0) +", '"+ escape_sql( strcharinfo(0) ) +"', "+ .@points +" ) on duplicate key update points = points + "+ .@points; end; } 1 Quote
Virtue Posted January 16, 2013 Author Posted January 16, 2013 Thanks Annie. this will help alot, im currently improving my know how on sql scripts. Quote
Question
Virtue
Hi, I am making myself an SQL Script,
now, how do i insert the character name to the sql_query? tried putting the exact name there but i got an error?
INSERT INTO `points` (char_id,name,points) VALUES (150000,????,1)
will it work if i made it like this
query_sql (INSERT INTO `points` (char_id,name,points) VALUES (150000,strcharinfo(0),1))
6 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.