RE: creating a SQL SELECT statement with javascript

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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" wrote:

> 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" wrote:
>
> > 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.
> > --
> > JJFJR
.



Relevant Pages

  • Problem capturing web data
    ... I have created two tables in an Access database as follows: ... I have created a Relationship from the userName Field in the Registration ... little Plus Sign to the left of the data, it opens up the fields for the ... straight forward task to just link two tables and capture data through an ...
    (microsoft.public.access.externaldata)
  • Re: Valid password characters
    ... > Often when one registers on different web sites around the world, ... > a pretty hard limitation on what characters I am allowed to use in my ... > username and password. ...
    (microsoft.public.inetserver.asp.db)
  • Application level password protection on Access 97 database
    ... I am interested in being able to set a username / password on my ... access database, so I can then set application level permissions, i.e. ... only let certain applications open the database without recoding the ... I know I can create user security with usernames and passwords to ...
    (microsoft.public.access.security)
  • Re: asp login and password to custom page?
    ... In your Access database, you'd have a field in the USERS table, along ... with username and password, that would be URL or something. ... When users log in, it checks their URL field and then does a ... I am using an access database connected through ODBC on a ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: pass CSS to page and launch it
    ... > obeys the statements in the stylesheet that was passed to it. ... > Access database. ... When Tom logs ... > JJFJR ...
    (microsoft.public.frontpage.programming)