creating a SQL SELECT statement with javascript

J

jjfjr

Hi;

I'm creating some javascript code in frontpage so that I can retrieve some
info from an MS Access database. The database has three fields: username,
password and stylesheet. I'm trying to retrieve the stylesheet value by
having a user input their username and password in a form. I then create a
SQL SELECT statement with the following code:

SQLstr = "SELECT [stylesheet] FROM userinfo WHERE
(([username] = '" + document.user_form.username.value + "') AND
([password] = '" + document.user_form.password.value + "'))";

When problem-free this will be used to access the info from the database via
a connection string. When I try to run the form page , I get an error that
says "Unterminated string constant line 22 column 51" . Line 22 column 51 is
the character v in value in the second line. I'm little a new to javascript
and not used to mixing single and double quotes; I had gotten this code from
reading some texts. Any help is greatly appreciated.
 
K

Klatuu

There are a couple of problems here.
1. The ; is in the wrong place.

2. The + in Access is a math symbol. Always use & when concatenating strings

3. The syntax for addressing a form is incorrect. The . is used for defined
objects, methods, and properties. The ! is used for User defined objects.

4. I am suspicious of document.user_form.username Even with the ! replacing
the . the format is incorrect. To address a control on a form in Access,
there are two methods. One method is for code in a form's module:
Me.MyControlName
The other is for addressing a control from another module:
forms!MyFormName!MyControlName

5. Although the .Value is correct, it is not necessary. It is the defaut
property returned. If you were to use it, the correct syntax is:
forms!MyFormName!MyControlName.value
Notice the . instead of the ! That is because Value is a property of a
control.

So, I don't know what document is here, so I can't completely resolve this.
Hopefully I have given you enough info to clean it up.


SQLstr = "SELECT [stylesheet] FROM userinfo WHERE
(([username] = '" & document!user_form!username & "') AND
([password] = '" & document!user_form!password & "'));"
 
J

jjfjr

Hi;

Thanks for the response. Let me give you a little more background as to what
I'm trying to do. I have a very simple MS Access database consisting of three
fields: username, password and stylesheet. What I want to do is allow a user
to input their username and password into a form (I'm using Frontpage) and
retrieve the associated style sheet which has specific rules. This
stylesheet will be passed to a browser so that the webpage will follow the
rules in the stylesheet. For example, if Tom (username:tom and password:mot)
inputs his info into the form, his stylesheet variable value (tom.css) will
be attached to the webpage I want to launch.

After the sqlstr variable is created, I have the following code:

// connection string construction
var strConn = "Driver={Microsoft Access Driver
(*.mdb)};DBQ=" + Server.MapPath("users.mdb");

// connection object creation
var dbConn = Server.CreateObject("ADODB.Connection");

// open the connection
dbConn.Open(strConn);

// Execute the query with constructed SQLstr
var rs = dbConn.Execute(SQLstr);
}

I want the variable rs to capture the stylesheet variable value and then
pass it to the page in the url like:

<a href="nextpage.asp?styles=<% rs %>"

and link it to the page to be launched like:

<link rel="stylesheet" type="text/css" href="/styles/<%=
request.querystring(styles) %>" media="screen">

In accordance with your recommendations, I changed my SELECT statement to:

SQLstr = "SELECT [stylesheet] FROM userinfo WHERE
(([username] = '" & user_form!username & "') AND
([password] = '" & user_form!password & "'));"

But I still get the same unterminated string constant error at line 22
column 51 which is at the very end of the second line . Any other ideas are
welcome.

Klatuu said:
There are a couple of problems here.
1. The ; is in the wrong place.

2. The + in Access is a math symbol. Always use & when concatenating strings

3. The syntax for addressing a form is incorrect. The . is used for defined
objects, methods, and properties. The ! is used for User defined objects.

4. I am suspicious of document.user_form.username Even with the ! replacing
the . the format is incorrect. To address a control on a form in Access,
there are two methods. One method is for code in a form's module:
Me.MyControlName
The other is for addressing a control from another module:
forms!MyFormName!MyControlName

5. Although the .Value is correct, it is not necessary. It is the defaut
property returned. If you were to use it, the correct syntax is:
forms!MyFormName!MyControlName.value
Notice the . instead of the ! That is because Value is a property of a
control.

So, I don't know what document is here, so I can't completely resolve this.
Hopefully I have given you enough info to clean it up.


SQLstr = "SELECT [stylesheet] FROM userinfo WHERE
(([username] = '" & document!user_form!username & "') AND
([password] = '" & document!user_form!password & "'));"

jjfjr said:
Hi;

I'm creating some javascript code in frontpage so that I can retrieve some
info from an MS Access database. The database has three fields: username,
password and stylesheet. I'm trying to retrieve the stylesheet value by
having a user input their username and password in a form. I then create a
SQL SELECT statement with the following code:

SQLstr = "SELECT [stylesheet] FROM userinfo WHERE
(([username] = '" + document.user_form.username.value + "') AND
([password] = '" + document.user_form.password.value + "'))";

When problem-free this will be used to access the info from the database via
a connection string. When I try to run the form page , I get an error that
says "Unterminated string constant line 22 column 51" . Line 22 column 51 is
the character v in value in the second line. I'm little a new to javascript
and not used to mixing single and double quotes; I had gotten this code from
reading some texts. Any help is greatly appreciated.
 
K

Klatuu

I understand the problem. It may be better if you tried your question in a
Java user group. This being an Access user group, I don't know that the
members here would be qualified to address this. I was approaching this from
a purely Access perspective which, it appears, is not going to be useful for
you.

Sorry I could not be of more help.

jjfjr said:
Hi;

Thanks for the response. Let me give you a little more background as to what
I'm trying to do. I have a very simple MS Access database consisting of three
fields: username, password and stylesheet. What I want to do is allow a user
to input their username and password into a form (I'm using Frontpage) and
retrieve the associated style sheet which has specific rules. This
stylesheet will be passed to a browser so that the webpage will follow the
rules in the stylesheet. For example, if Tom (username:tom and password:mot)
inputs his info into the form, his stylesheet variable value (tom.css) will
be attached to the webpage I want to launch.

After the sqlstr variable is created, I have the following code:

// connection string construction
var strConn = "Driver={Microsoft Access Driver
(*.mdb)};DBQ=" + Server.MapPath("users.mdb");

// connection object creation
var dbConn = Server.CreateObject("ADODB.Connection");

// open the connection
dbConn.Open(strConn);

// Execute the query with constructed SQLstr
var rs = dbConn.Execute(SQLstr);
}

I want the variable rs to capture the stylesheet variable value and then
pass it to the page in the url like:

<a href="nextpage.asp?styles=<% rs %>"

and link it to the page to be launched like:

<link rel="stylesheet" type="text/css" href="/styles/<%=
request.querystring(styles) %>" media="screen">

In accordance with your recommendations, I changed my SELECT statement to:

SQLstr = "SELECT [stylesheet] FROM userinfo WHERE
(([username] = '" & user_form!username & "') AND
([password] = '" & user_form!password & "'));"

But I still get the same unterminated string constant error at line 22
column 51 which is at the very end of the second line . Any other ideas are
welcome.

Klatuu said:
There are a couple of problems here.
1. The ; is in the wrong place.

2. The + in Access is a math symbol. Always use & when concatenating strings

3. The syntax for addressing a form is incorrect. The . is used for defined
objects, methods, and properties. The ! is used for User defined objects.

4. I am suspicious of document.user_form.username Even with the ! replacing
the . the format is incorrect. To address a control on a form in Access,
there are two methods. One method is for code in a form's module:
Me.MyControlName
The other is for addressing a control from another module:
forms!MyFormName!MyControlName

5. Although the .Value is correct, it is not necessary. It is the defaut
property returned. If you were to use it, the correct syntax is:
forms!MyFormName!MyControlName.value
Notice the . instead of the ! That is because Value is a property of a
control.

So, I don't know what document is here, so I can't completely resolve this.
Hopefully I have given you enough info to clean it up.


SQLstr = "SELECT [stylesheet] FROM userinfo WHERE
(([username] = '" & document!user_form!username & "') AND
([password] = '" & document!user_form!password & "'));"

jjfjr said:
Hi;

I'm creating some javascript code in frontpage so that I can retrieve some
info from an MS Access database. The database has three fields: username,
password and stylesheet. I'm trying to retrieve the stylesheet value by
having a user input their username and password in a form. I then create a
SQL SELECT statement with the following code:

SQLstr = "SELECT [stylesheet] FROM userinfo WHERE
(([username] = '" + document.user_form.username.value + "') AND
([password] = '" + document.user_form.password.value + "'))";

When problem-free this will be used to access the info from the database via
a connection string. When I try to run the form page , I get an error that
says "Unterminated string constant line 22 column 51" . Line 22 column 51 is
the character v in value in the second line. I'm little a new to javascript
and not used to mixing single and double quotes; I had gotten this code from
reading some texts. Any help is greatly appreciated.
 
B

Brendan Reynolds

I'm no expert on JavaScript, but as far as I can tell the code you
originally posted was correct as far as string concatenation is concerned.
The syntax appears to be quite similar to C#, and if I replace the
references to the form with string variables the code compiles without error
and results in a valid SQL string in C#. All this leads me to suspect that
the problem is actually something to do with the references to the form, and
that therefore this is very much a JavaScript and not an Access problem. As
suggested elsewhere in this thread, you're probably more likely to find the
solution in a JavaScript forum.

--
Brendan Reynolds (MVP)

jjfjr said:
Hi;

Thanks for the response. Let me give you a little more background as to
what
I'm trying to do. I have a very simple MS Access database consisting of
three
fields: username, password and stylesheet. What I want to do is allow a
user
to input their username and password into a form (I'm using Frontpage) and
retrieve the associated style sheet which has specific rules. This
stylesheet will be passed to a browser so that the webpage will follow
the
rules in the stylesheet. For example, if Tom (username:tom and
password:mot)
inputs his info into the form, his stylesheet variable value (tom.css)
will
be attached to the webpage I want to launch.

After the sqlstr variable is created, I have the following code:

// connection string construction
var strConn = "Driver={Microsoft Access Driver
(*.mdb)};DBQ=" + Server.MapPath("users.mdb");

// connection object creation
var dbConn = Server.CreateObject("ADODB.Connection");

// open the connection
dbConn.Open(strConn);

// Execute the query with constructed SQLstr
var rs = dbConn.Execute(SQLstr);
}

I want the variable rs to capture the stylesheet variable value and then
pass it to the page in the url like:

<a href="nextpage.asp?styles=<% rs %>"

and link it to the page to be launched like:

<link rel="stylesheet" type="text/css" href="/styles/<%=
request.querystring(styles) %>" media="screen">

In accordance with your recommendations, I changed my SELECT statement to:

SQLstr = "SELECT [stylesheet] FROM userinfo WHERE
(([username] = '" & user_form!username & "') AND
([password] = '" & user_form!password & "'));"

But I still get the same unterminated string constant error at line 22
column 51 which is at the very end of the second line . Any other ideas
are
welcome.

Klatuu said:
There are a couple of problems here.
1. The ; is in the wrong place.

2. The + in Access is a math symbol. Always use & when concatenating
strings

3. The syntax for addressing a form is incorrect. The . is used for
defined
objects, methods, and properties. The ! is used for User defined
objects.

4. I am suspicious of document.user_form.username Even with the !
replacing
the . the format is incorrect. To address a control on a form in Access,
there are two methods. One method is for code in a form's module:
Me.MyControlName
The other is for addressing a control from another module:
forms!MyFormName!MyControlName

5. Although the .Value is correct, it is not necessary. It is the defaut
property returned. If you were to use it, the correct syntax is:
forms!MyFormName!MyControlName.value
Notice the . instead of the ! That is because Value is a property of a
control.

So, I don't know what document is here, so I can't completely resolve
this.
Hopefully I have given you enough info to clean it up.


SQLstr = "SELECT [stylesheet] FROM userinfo WHERE
(([username] = '" & document!user_form!username & "') AND
([password] = '" & document!user_form!password & "'));"

jjfjr said:
Hi;

I'm creating some javascript code in frontpage so that I can retrieve
some
info from an MS Access database. The database has three fields:
username,
password and stylesheet. I'm trying to retrieve the stylesheet value by
having a user input their username and password in a form. I then
create a
SQL SELECT statement with the following code:

SQLstr = "SELECT [stylesheet] FROM userinfo WHERE
(([username] = '" + document.user_form.username.value + "') AND
([password] = '" + document.user_form.password.value + "'))";

When problem-free this will be used to access the info from the
database via
a connection string. When I try to run the form page , I get an error
that
says "Unterminated string constant line 22 column 51" . Line 22 column
51 is
the character v in value in the second line. I'm little a new to
javascript
and not used to mixing single and double quotes; I had gotten this code
from
reading some texts. Any help is greatly appreciated.
 
U

User

jjfjr said:
Hi;

Thanks for the response. Let me give you a little more background as to what
I'm trying to do. I have a very simple MS Access database consisting of three
fields: username, password and stylesheet. What I want to do is allow a user
to input their username and password into a form (I'm using Frontpage) and
retrieve the associated style sheet which has specific rules. This
stylesheet will be passed to a browser so that the webpage will follow the
rules in the stylesheet. For example, if Tom (username:tom and password:mot)
inputs his info into the form, his stylesheet variable value (tom.css) will
be attached to the webpage I want to launch.

After the sqlstr variable is created, I have the following code:

// connection string construction
var strConn = "Driver={Microsoft Access Driver
(*.mdb)};DBQ=" + Server.MapPath("users.mdb");

// connection object creation
var dbConn = Server.CreateObject("ADODB.Connection");

// open the connection
dbConn.Open(strConn);

// Execute the query with constructed SQLstr
var rs = dbConn.Execute(SQLstr);
}

I want the variable rs to capture the stylesheet variable value and then
pass it to the page in the url like:

<a href="nextpage.asp?styles=<% rs %>"

and link it to the page to be launched like:

<link rel="stylesheet" type="text/css" href="/styles/<%=
request.querystring(styles) %>" media="screen">

In accordance with your recommendations, I changed my SELECT statement to:

SQLstr = "SELECT [stylesheet] FROM userinfo WHERE
(([username] = '" & user_form!username & "') AND
([password] = '" & user_form!password & "'));"

But I still get the same unterminated string constant error at line 22
column 51 which is at the very end of the second line . Any other ideas are
welcome.


Jscript likes to denote strings with the single quote (but double quote is
also acceptable)
Jscrpit uses + for string concatenation (but maybe & is ok)
Access likes to denote strings with double qoutes.
I do not quite understand your form references. They look like Access style
references rather than jscript/asp references.
So assuming the above code is in an ASP page that handles the posting of the
form, I would guess:

var uname = Request('username')() ; // the extra () is important
var pword = Request('password')() ; // the extra () is important

var SQLstr = 'SELECT [stylesheet] FROM userinfo WHERE [username] = "'
+ uname + '" AND [password] = "' + pname ;

Upon proper evaluation we want SQLstr to be:
SELECT [stylesheet] FROM userinfo WHERE [username] = "uuu" AND
[password] = "ppp"

=====
The above is not tested syntax and should be scruntinized carefully.
However maybe the considerations therein may help.
 
U

User

User said:
jjfjr said:
Hi;

Thanks for the response. Let me give you a little more background as to what
I'm trying to do. I have a very simple MS Access database consisting of three
fields: username, password and stylesheet. What I want to do is allow a user
to input their username and password into a form (I'm using Frontpage) and
retrieve the associated style sheet which has specific rules. This
stylesheet will be passed to a browser so that the webpage will follow the
rules in the stylesheet. For example, if Tom (username:tom and password:mot)
inputs his info into the form, his stylesheet variable value (tom.css) will
be attached to the webpage I want to launch.

After the sqlstr variable is created, I have the following code:

// connection string construction
var strConn = "Driver={Microsoft Access Driver
(*.mdb)};DBQ=" + Server.MapPath("users.mdb");

// connection object creation
var dbConn = Server.CreateObject("ADODB.Connection");

// open the connection
dbConn.Open(strConn);

// Execute the query with constructed SQLstr
var rs = dbConn.Execute(SQLstr);
}

I want the variable rs to capture the stylesheet variable value and then
pass it to the page in the url like:

<a href="nextpage.asp?styles=<% rs %>"

and link it to the page to be launched like:

<link rel="stylesheet" type="text/css" href="/styles/<%=
request.querystring(styles) %>" media="screen">

In accordance with your recommendations, I changed my SELECT statement to:

SQLstr = "SELECT [stylesheet] FROM userinfo WHERE
(([username] = '" & user_form!username & "') AND
([password] = '" & user_form!password & "'));"

But I still get the same unterminated string constant error at line 22
column 51 which is at the very end of the second line . Any other ideas are
welcome.

(OOPS ... left out trailing double-quote)

Jscript likes to denote strings with the single quote (but double quote is
also acceptable)
Jscrpit uses + for string concatenation (but maybe & is ok)
Access likes to denote strings with double qoutes.
I do not quite understand your form references. They look like Access style
references rather than jscript/asp references.
So assuming the above code is in an ASP page that handles the posting of the
form, I would guess:

var uname = Request('username')() ; // the extra () is important
var pword = Request('password')() ; // the extra () is important

var SQLstr = 'SELECT [stylesheet] FROM userinfo WHERE [username] = "'
+ uname + '" AND [password] = "' + pname + '"' ;

Upon proper evaluation we want SQLstr to be:
SELECT [stylesheet] FROM userinfo WHERE [username] = "uuu" AND
[password] = "ppp"

=====
The above is not tested syntax and should be scruntinized carefully.
However maybe the considerations therein may help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top