By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,656 Members | 748 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,656 IT Pros & Developers. It's quick & easy.

ASP link back to Access database

P: n/a
I am having great difficulty in these asp scripts, using VBscript and
JavaScript.

I have 4 files that all need to be linked together.

The first file "Books.html" - needs to search for a Book title, author
or ISBN number from a Access database called "Books.mdb". When the
user clicks Submit from the "Books.html" file (after inputting info in
a text box and clicking the required box to define Title, Author or
ISBN), the information is then filtered through "Books.asp" file and
"CreateTable.asp" file.

<PLEASE SEE MY FILES and coding below this message, didn't know how to
attach files - files below: Books.asp; Books.inc; Books.html and
CreateTable.asp. Not shown is Books.mdb Access database file.

My problem is this: I cannot get the script in the Books.asp file to
only bring up certain information pertaining to that in my search box
from the "Books.html" file. What happens, is a) I get a error message
when I try and debug it or b) the full table comes up.

HELP !

I am using Abysse web server under http://localhost port8080.

Can anyone please help.. Any feedback most appreciated. My personal
e-mail is ks*****@shaw.ca for any step by step instructions you can
offer.

Thank you so much.

PS - yah, you guessed it, this is a URGENT request too. :)

Expand|Select|Wrap|Line Numbers
  1. "BOOKS.ASP file"
Expand|Select|Wrap|Line Numbers
  1. <HTML>
  2.  
  3. <!--#INCLUDE FILE="Books.inc" -->
  4. <!--#INCLUDE FILE="ADOVBS.inc" -->
  5. <!--#INCLUDE FILE="CreateTable.asp" -->
  6.  
  7. <HEAD>
  8.  
  9. <TITLE>Accessing a Data Store using DSN (Data Source Name) with Active
  10. Server Pages </TITLE>
  11.  
  12. </HEAD>
  13. <BODY>
  14.  
  15. <%
  16. Dim objConn
  17. Dim objRec
  18.  
  19. Dim CheckISBN
  20. Dim CheckTitle
  21. Dim CheckAuthor
  22. Dim SearchString
  23. Dim found
  24.  
  25. objConn.Open strConnect
  26. objRec.Open "Titles",strConnect,adOpenStatic,adLockReadOnly,adCmdTable
  27. objRec.MoveFirst
  28. Response.Write CreateTable(objRec)
  29.  
  30. found=0
  31. CheckISBN=Request.Form("chkISBN")
  32. CheckTitle=Request.Form("chkTitle")
  33. CheckAuthor=Request.Form("chkAuthor")
  34.  
  35. SearchString=Request.Form("txtSearch")
  36.  
  37. Set objConn=Server.CreateObject("ADODB.Connection")
  38. Set objRec=Server.CreateObject("ADODB.RecordSet")
  39.  
  40. objConn.Open strConnect
  41.  
  42. objRec.Open "Titles",strConnect,adOpenStatic,adLockReadOnly,adCmdtable
  43. objRec.MoveFirst
  44.  
  45. If CheckISBN = "ByISBN" Then
  46. objRec.Find "ISBN= '"& Request.Form("txtSearch") & "'"
  47.  
  48. If Not objRec.EOF Then
  49. found=1
  50. Response.Write objRec("ISBN")
  51. Response.Write "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
  52. Response.Write objRec("Price")
  53. Response.Write "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
  54. Response.Write objRec("Title") & "<BR>"
  55. End if
  56. End if
  57.  
  58. If CheckTitle = "ByTitle" Then
  59. objRec.Find "Title= '"& Request.Form("txtSearch") & "'"
  60.  
  61. If Not objRec.EOF Then
  62. found=1
  63. Response.Write objRec("ISBN")
  64. Response.Write "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
  65. Response.Write objRec("Price")
  66. Response.Write "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
  67. Response.Write objRec("Title") & "<BR>"
  68. End if
  69. End if
  70.  
  71. If CheckAuthor = "ByAuthor" Then
  72. objRec.Filter = "Author= '"& Request.Form("txtSearch") & "'"
  73.  
  74. While Not objRec.EOF
  75. If objRec("Author") = SearchString Then
  76. found=1
  77. Response.Write objRec("ISBN")
  78. Response.Write "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
  79. Response.Write objRec("Price")
  80. Response.Write "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
  81. Response.Write objRec("Title") & "<BR>"
  82. End if
  83.  
  84. objRec.MoveNext
  85. Wend
  86. If found=0 Then
  87. Response.Write "Record Not Found"
  88. End if
  89. End if
  90.  
  91. objRec.Close
  92. objConn.Close
  93. Set objRec=Nothing
  94. Set objConn=Nothing
  95.  
  96.  
  97. </BODY>
  98. </HTML>
  99.  
Expand|Select|Wrap|Line Numbers
  1. BOOKS.INC file
Expand|Select|Wrap|Line Numbers
  1. <HTML>
  2.  
  3. <HEAD>
  4.  
  5. <TITLE>Location specific records in a database, with DSN and Active
  6. Server Pages </TITLE>
  7.  
  8. </HEAD>
  9.  
  10. <BODY>
  11.  
  12. <%
  13. strConnect = "Driver={Microsoft Access Driver
  14. (*.mdb)};DBQ=c:\inetpub\wwwroot\K_Orman\Books.mdb;"
  15. %>
  16.  
  17. </BODY>
  18. </HTML>
  19.  
Expand|Select|Wrap|Line Numbers
  1. BOOKS.HTML file
<HTML>

<HEAD>

<TITLE> Location Specifc Records - Active Server Pages, Connecting to
DSN - PART 3</TITLE>

</HEAD>

<BODY>

<FORM NAME="frmsearch" ACTION="Books.asp" METHOD="Post">

<H3> Please enter the Title, the Author, or the ISBN number of the
book(s) you wish to search for: </H3>

<INPUT TYPE="text" NAME="txtSearch"><BR>

Search by: <BR>

<INPUT TYPE="checkbox" NAME="chkTitle" VALUE="ByTitle"> Title <BR>
<INPUT TYPE="checkbox" NAME="chkAuthor" VALUE="ByAuthor"> Author <BR>
<INPUT TYPE="checkbox" NAME="chkISBN" VALUE="ByISBN"> ISBN
<BR><BR><BR>
<INPUT TYPE="submit" NAME="cmdSearch" VALUE="Search"><BR>
<INPUT TYPE="Reset" NAME="cmdreset" VALUE="Reset">
</FORM>

</BODY>
</HTML>
[/code]

Expand|Select|Wrap|Line Numbers
  1. CREATETABLE.asp file
Expand|Select|Wrap|Line Numbers
  1. <HTML>
  2.  
  3. <HEAD>
  4.  
  5. <TITLE> Active Server Pages - Data Name Source </TITLE>
  6.  
  7. </HEAD>
  8.  
  9. <BODY>
  10.  
  11. <%
  12. Function CreateTable(objRecordset)
  13.  
  14. Dim fldField
  15. Dim strTable
  16.  
  17. strTable = "<TABLE BORDER=2>" & "<TR ALIGN=CENTER>"
  18.  
  19. For Each fldField in objRecordset.Fields
  20. strTable = strTable & "<TD>" & fldField.Name & "</TD>"
  21. Next
  22.  
  23. strTable = strTable & "</TR>"
  24.  
  25. While not objRecordset.EOF
  26. strTable = strTable & "<TR ALIGN=CENTER>"
  27.  
  28. For Each fldField in objRecordset.Fields
  29. strTable= strTable & "<TD>" & fldField.Value & "</TD>"
  30. Next
  31.  
  32. strTable= strTable & "</TR>"
  33. objRecordset.MoveNext
  34.  
  35. Wend
  36.  
  37. strTable = strTable & "</TABLE>"
  38.  
  39. CreateTable = strTable
  40.  
  41. End Function
  42.  
  43. %>
  44.  
  45. </BODY>
  46. </HTML>
  47.  
[/quote][/code] THANK YOU SO MUCH.....
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
In article <fa**************************@posting.google.com >,
ks*****@shaw.ca enlightened us with...
I am having great difficulty in these asp scripts, using VBscript and
JavaScript.

I didn't see any javascript.
But, I'm pretty okey-dokey with VBScript, so...
I have 4 files that all need to be linked together.

My problem is this: I cannot get the script in the Books.asp file to
only bring up certain information pertaining to that in my search box
from the "Books.html" file. What happens, is a) I get a error message
when I try and debug it or b) the full table comes up.

HELP !

My guess is that you're not getting the search string you think you are.
CheckISBN=Request.Form("chkISBN")
CheckTitle=Request.Form("chkTitle")
CheckAuthor=Request.Form("chkAuthor")

Write these to output with a Request.Write and end the page there (test
page if you want).
I bet they don't match

If CheckISBN = "ByISBN" Then


that sort of thing.

I bet you get a one or a true. That is, CheckISBN will either be "1" or
"true" which would completely mess up your query and cause the selection
of all records.
Checkboxes get passed as true/false, I think...
like chkISBN=true in the query string.

Just change the method of the form to get and look at the URL to see if
you don't want to write the stuff on the page.

--
--
~kaeli~
Never mess up an apology with an excuse.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #2

P: n/a
Thanks Kaeli,

You probably guessed that I'm new at this vbscripting code thing - so
would you please reply with the correct code to the specific file that
needs it. Or send me a e-mail.

I'm a bit lost in your reply.

Thanks.
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #3

P: n/a
In article <40**********************@news.newsgroups.ws>,
ks*****@shaw.ca enlightened us with...
Thanks Kaeli,

You probably guessed that I'm new at this vbscripting code thing - so
would you please reply with the correct code to the specific file that
needs it. Or send me a e-mail.

I'm a bit lost in your reply.


Okay, I did a little check. My idea was not what was causing the
problem. But it was something similar.
Your search string is empty. For some reason,
SearchString=Request.Form("txtSearch")
is returning a blank. I don't know why, since it shows in the URL when I
do a GET and from POST when I loop through all form elements (see test
file).

This smacks of a school assignment, so you may want to ask your teacher.
The following is a test I did to see what the form was submitting. Run
it and you'll see what's wrong. I don't know if it's a server thing or
what. I've never seen this problem with unencoded forms. I gotta go home
now, so you won't see a reply from me 'til Monday.

test.asp
<HTML>
<HEAD>
<TITLE> Location Specifc Records - Active Server Pages, Connecting to
DSN - PART 3</TITLE>
</HEAD>
<BODY>
<FORM NAME="frmsearch" ACTION="test1.asp" METHOD="post">
<H3> Please enter the Title, the Author, or the ISBN number of the
book(s) you wish to search for: </H3>
<INPUT TYPE="text" NAME="txtSearch"><BR>
Search by: <BR>
<INPUT TYPE="checkbox" NAME="chkTitle" VALUE="ByTitle"> Title <BR>
<INPUT TYPE="checkbox" NAME="chkAuthor" VALUE="ByAuthor"> Author <BR>
<INPUT TYPE="checkbox" NAME="chkISBN" VALUE="ByISBN"> ISBN
<BR><BR><BR>
<INPUT TYPE="submit" NAME="cmdSearch" VALUE="Search"><BR>
<INPUT TYPE="Reset" NAME="cmdreset" VALUE="Reset">
</FORM>
</BODY>
</HTML>

test1.asp
<%@ Language=VBScript %>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<p>This is a test page for the form submit values.</p>
<p>
CheckISBN=<%= Request.Form("chkISBN") %>
CheckTitle=<%= Request.Form("chkTitle") %>
CheckAuthor=<%= Request.Form("chkAuthor") %>
SearchString=<% Request.Form("txtSearch") %>
</p>
<%
Dim f
For Each f In Request.Form
Response.Write f & " = "
Response.Write Request.Form(f) & "<br>"
Next
%>
</body>
</html>
--
--
~kaeli~
Can you be a closet claustrophobic?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.