passing an Access variable to a page

J

jjfjr

Hi;

I'm creating an application that has the user fill out a form with a
username and password. The name and password are sent to an MS Access
database and a third piece of information is retrieved. This information is
the name of a cascading style sheet e.g. "tom.css". I want to pass this
string to a webpage so it will obey the rules in the CSS. The Access database
rows consist of the fields username, password and stylesheet.

My code to get the CSS info via the form is as follows:

if ((username == "") || (username == null))
alert("You must enter a username.");

if ((password == "") || (password == null))
alert("You must enter a password.");

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

The code to connect to the database looks like this:

// 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'm planning to put the following code in the form page to pass the result
of the query to the page ("Gettysburg. htm") that will follow the CSS rules:

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

Will the variable rs have captured the CSS string?

I was then going to put the following code in the HEAD of the Gettysburg
page in order to link things up:

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

Does this sound like it should work?
Any help is greatly appreciated.
 
K

Kevin Spencer

Let me get this straight. You've written a bunch of code that you plan to
use in an ASP application, copied and pasted it into an newsgroup post, and
are asking "does this sound like it should work?" So, if I can retrace your
steps here a bit, you spent a certain amount of time writing this code. Then
you spent a certain amount of time writing this newsgroup post, and pasting
the code into the post. Then you sent the post, and have spent a certain
amount of time (looks like give or take 12 hours) waiting for a response as
to whether the code should work.

.... ... ...

What am I missing here? It seems ligical to me that you would write the
code, and then try it out to see whether it works or not. If you had done
so, you would have known the answer quite some time ago. Believe it or not,
this is a legitimate method for checking your code, that is, trying it out.
I do it all the time. That's why development environments have debuggers. So
you can run your code, see if it works, and when it doesn't (which it
usually doesn't the first couple of times), figure out why.

So, here's my suggestion: Although there is not a reliable debugger for ASP,
you can certainly run it (your code) to see whether or not it has bugs in
it. When it doesn't, employ analytical skills to figure out why not. If you
need to see how things are going at various phases of the code, put in
Response.Write() statements in your code to find out the values of different
things along the way. This will also give you an opportunity to see where it
breaks. For example, if a certain Response.Write() statement does not
execute, you know that the code broke prior to that statement.

If your analytical skills are lacking somewhat, don't worry. So are everyone
else's. But practice makes perfect! ;-)

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.


jjfjr said:
Hi;

I'm creating an application that has the user fill out a form with a
username and password. The name and password are sent to an MS Access
database and a third piece of information is retrieved. This information
is
the name of a cascading style sheet e.g. "tom.css". I want to pass this
string to a webpage so it will obey the rules in the CSS. The Access
database
rows consist of the fields username, password and stylesheet.

My code to get the CSS info via the form is as follows:

if ((username == "") || (username == null))
alert("You must enter a username.");

if ((password == "") || (password == null))
alert("You must enter a password.");

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

The code to connect to the database looks like this:

// 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'm planning to put the following code in the form page to pass the result
of the query to the page ("Gettysburg. htm") that will follow the CSS
rules:

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

Will the variable rs have captured the CSS string?

I was then going to put the following code in the HEAD of the Gettysburg
page in order to link things up:

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

Does this sound like it should work?
Any help is greatly appreciated.
 

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