Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Sep 2002
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    trouble with insert into db with jscript

    hello
    using mysql server with asp and jscript
    it looks like the jscript doesn't like "" around variables in the insert string....
    can anyone help me on how to get the value of a variable into this?
    here are some things i've tried:

    var insertBird=Request.Form("txtBird");
    result=conn.Execute("INSERT INTO birds VALUES('$insertBird$')");
    // database gets "$insertBird$"
    result=conn.Execute("INSERT INTO birds VALUES('$insertBird')");
    // database gets "$insertBird"
    result=conn.Execute("INSERT INTO birds VALUES('insertBird')");
    // database error that there is no col "insertbird"
    result=conn.Execute("INSERT INTO birds VALUES('"insertBird"')");
    // jscript error that it expects ";" after "('"

    anyone help on this?
    thanks in advance

  • #2
    Regular Coder
    Join Date
    Sep 2002
    Location
    Bulgaria
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,
    Should $insertBird$ be a JScript variable or a string constant?
    If it's a variable then
    result=conn.Execute("INSERT INTO birds VALUES(\"" + insertBird + "\")");
    should be correct syntax.
    If it's a string constant then:
    result=conn.Execute("INSERT INTO birds VALUES(\"insertBird\")");
    should be what You want.

    Alex

  • #3
    New to the CF scene
    Join Date
    Sep 2002
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi
    thanks for the reply
    insertBird is supposed to be a variable
    what works is

    result=conn.Execute("INSERT INTO birds VALUES('"+insertBird+"')");
    // value in insertBird does to database :-)

    result=conn.Execute("INSERT INTO birds VALUES(\""+insertBird+"\")");
    // also value in insertBird goes to database :-)

    so another question is, does it matter which of the 2 ways above are used since they both seem to work?
    is one syntactically better or more likely to keep me out of trouble?
    thanks again
    cheers

  • #4
    Regular Coder
    Join Date
    Sep 2002
    Location
    Bulgaria
    Posts
    123
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,
    It depends on what Your database accepts as string delimiter...
    Some of them accept only single quote, some of them double and some of them both... You have to evaluate what is Your database, will it evolve and to which one to answer Your question...
    Your first example sends the SQL statement with single quote string delimiter, second one with double quote. mySQL supports both syntaxes.

    Alex


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •