Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Code:

function setvalue(val) {

        idoutput=val;
        base62val=Base.encode(idoutput);
        var baseinsert = {ShortUrlCode:base62val};
        console.log(idoutput);
        console.log(base62val);
        con.query('INSERT INTO URLTABLE set ?  where ID = ?',[baseinsert,idoutput],function(err){
        if(err) console.log(err);
        })
        console.log("short inserted");
        con.end();
}

Error I am receiving:

{ [Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where ID = 38' at line 1]
  code: 'ER_PARSE_ERROR',
  errno: 1064,
  sqlState: '42000',
  index: 0 }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
198 views
Welcome To Ask or Share your Answers For Others

1 Answer

'INSERT INTO URLTABLE set ?  where ID = ?'

You forgot to mention column names that you want to "SET".

 'INSERT INTO URLTABLE SET column_name = ? (, column_name2 = ?,...) WHERE ID = ?'

is the correct syntax

EDIT:

Note that it is always better to "standardize" your SQL queries, in which case you better use the standard SQL syntax below for an INSERT (instead of using your specific MySQL syntax):

INSERT INTO URLTABLE (a, b, c) VALUES (?,?,?)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...