Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-23-2002, 07:00 AM   PM User | #1
bigdude
New to the CF scene

 
Join Date: Sep 2002
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
bigdude is an unknown quantity at this point
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
bigdude is offline   Reply With Quote
Old 09-23-2002, 09:23 AM   PM User | #2
Alekz
Regular Coder

 
Join Date: Sep 2002
Location: Bulgaria
Posts: 123
Thanks: 0
Thanked 0 Times in 0 Posts
Alekz is on a distinguished road
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
Alekz is offline   Reply With Quote
Old 09-23-2002, 09:18 PM   PM User | #3
bigdude
New to the CF scene

 
Join Date: Sep 2002
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
bigdude is an unknown quantity at this point
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
bigdude is offline   Reply With Quote
Old 09-24-2002, 07:41 AM   PM User | #4
Alekz
Regular Coder

 
Join Date: Sep 2002
Location: Bulgaria
Posts: 123
Thanks: 0
Thanked 0 Times in 0 Posts
Alekz is on a distinguished road
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
Alekz is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:32 AM.


Advertisement
Log in to turn off these ads.