Please support our sponsors
7/26/00
 Quick Links :
home| forum | whats new | advertise | contact us




Overview
Access Database
Indexing using HTTP protocol
Indexing using FilySystemObject
Deleting URLs from Database
HTML Search Engine Form
Searching Records in the Database
Include File
Conclusion

WantJava.com


Wrox Conferences

Creating 'addtodb.asp' page :

Open note pad or your favorite text editor and create a new page. Save it as 'addtodb.asp'. Now copy paste the following code into it :

   <!--#include file="editme.asp"-->
   <html>
   <head>
      <style>
         body { font-family : Verdana; font-size : 8pt; }
      </style>
   </head>
   <body>

 <%    On Error Resume Next
   Dim geturl, title, description, keywords, strURL, strDB, con, results

      ' URL
      strURL = Request.QueryString("look_for")

      Set geturl = CreateObject("Stardeveloper.GetURL")
      strFileContents = geturl.Get(strURL)
      Set geturl = Nothing

      ' Keywords
      key1 = InStr(1, strFileContents, "<meta name=""keywords"" content=""", 1)
      key1 = key1 + Len("<meta name=""keywords"" content=""")
      key2 = InStr(key1, strFileContents, """>", 1)

      keywords = "," & Trim(Mid(strFileContents, key1, (key2 - key1))) & ","
      keywords = Replace (keywords, "'", " ")

      ' Description
      desc1 = InStr(1, strFileContents, "<meta name=""description"" content=""", 1)
      desc1 = desc1 + Len("<meta name=""description"" content=""")
      desc2 = InStr(desc1, strFileContents, """>", 1)

      description = Trim(Mid(strFileContents, desc1, (desc2 - desc1)))
      description = Replace (description, "'", " ")

      ' Title
      tit1 = InStr(1, lcase(strFileContents), "<title>", 1)
      tit1 = tit1 + Len("<title>")
      tit2 = InStr(tit1, strFileContents, "</title>", 1)

      title = Trim(Mid(strFileContents, tit1, (tit2 - tit1)))
      title = Replace (title, "'", " ")

      ' Our Connection Object
      Set con = CreateObject("ADODB.Connection")
      con.Open strDB
      Set results = con.Execute("select title, description, keywords _
                  from all_pages where url = '" & strURL & "'")

      ' If the returning recordset is empty the add the URL with accompanying
      ' info to the database
      If results.EOF Then
         con.Execute("insert into all_pages (title, description, keywords, url, _
                  mydate) values ('" & title & "', '" & description & "', '" & _
                  keywords & "', '" & strURL & "', '" & date & "')")
         Set rs = con.Execute("select count(url) as total_count from all_pages")
         cnt = rs("total_count")
         Set rs = Nothing
         Response.Write "<b>New account successfully created for " & strURL & " _
                  .</b>" & vbcrlf
         Response.Write "<br>"
         Response.Write "Total Pages Indexed : " & cnt & vbcrlf
      Else
      ' But if the returning recordset is not empty i.e. we have already added _
      ' title, desc, keywords etc into it then update that information with the _
      ' new one.
         con.Execute("update all_pages set title = '" & title & "', description = _
                  '" & description & "', keywords = '" & keywords & "', mydate = #" _
                  & date & "# where url = '" & strURL & "'")
         Response.Write "<b>Account updated successfully.</b>"
      End If

      ' Done. Now release Objects
      Set results = Nothing
      con.Close
      Set con = Nothing

 %>
   </body></html>

Reviewing the code :

We will now very quickly look into the code and see how it's done. Although this page might seem a bit long, but if you carefully look into it, all it contains are simple VBScript function calls and nothing more than that.

   <!--#include file="editme.asp"-->

This is first line of the page. All it does is to include 'editme.asp' file into this page. 'editme.asp' contains a single variable to store the relative location of the database. We will look into 'editme.asp' page later.

On the next page we continue with the exploration of 'addtodb.asp' page.



Next -> 




Please support our sponsors

© 1999-2000 Faisal Khan, All rights reserved