Jump to content
  • 0

SQL Script support


Virtue

Question


  • Group:  Members
  • Topic Count:  92
  • Topics Per Day:  0.02
  • Content Count:  354
  • Reputation:   22
  • Joined:  11/17/11
  • Last Seen:  

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))

Link to comment
Share on other sites

6 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  9
  • Topics Per Day:  0.00
  • Content Count:  379
  • Reputation:   304
  • Joined:  11/10/11
  • Last Seen:  

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')");

  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  92
  • Topics Per Day:  0.02
  • Content Count:  354
  • Reputation:   22
  • Joined:  11/17/11
  • Last Seen:  

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 + "')");

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  9
  • Topics Per Day:  0.00
  • Content Count:  379
  • Reputation:   304
  • Joined:  11/10/11
  • Last Seen:  

Yeah it should.

But you don't need escape_sql() on an INT variable :P just on string.

  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  92
  • Topics Per Day:  0.02
  • Content Count:  354
  • Reputation:   22
  • Joined:  11/17/11
  • Last Seen:  

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);

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.00
  • Content Count:  2044
  • Reputation:   682
  • Joined:  10/09/12
  • Last Seen:  

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;
}

  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  92
  • Topics Per Day:  0.02
  • Content Count:  354
  • Reputation:   22
  • Joined:  11/17/11
  • Last Seen:  

Thanks Annie. this will help alot, im currently improving my know how on sql scripts.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...