Avatar billede dennisn Nybegynder
26. maj 2001 - 01:43 Der er 5 kommentarer og
1 løsning

Tilføj ny URL

Jeg har et styk asp side, hvor folk meget gerne skulle kunne tilføje deres side til min database, hvorefter man så kan søge på dem, problemmet er at når man tilføjer en side kommer der sgu ikke noget i databasen. Er der en der lige har lyst til at se lidt på det, så det kan komme til at virke ?
DU/I kan skrive til mig på dennis@dennisn.dk
eller icq 12460644
Avatar billede nuno Nybegynder
26. maj 2001 - 01:51 #1
hvorfor poster du ikke spørgsmålet her? Det er jo meningen at eventuelle andre brugere med samme problem skal kunne få glæde af et svar.

/nuno
Avatar billede dennisn Nybegynder
26. maj 2001 - 02:01 #2
Wow du er hurtig ??
jeg har en side http://www.dennisn.dk/add_url.htm
med form og hele muleviten og en side der hedder http://www.dennisn.dk/add_url.asp som skulle få den form over i databasen men det gør den bare ikke !
Avatar billede dennisn Nybegynder
26. maj 2001 - 02:03 #3
Forkert adresse:
den hedder http://www.dennisn.dk/add_url_form.htm
Avatar billede madrich Nybegynder
26. maj 2001 - 02:32 #4
Du bliver nødt til at vise os Sql og de variabler du kalder,ellers kan man squ ikke hjælpe, da man jo ikke lige kan tage sourcen fra et ASP-dok.
Avatar billede dennisn Nybegynder
26. maj 2001 - 10:24 #5
Jamen i kan da se hele asp koden ! (meget langt)

--- add_url.asp
<%
\'Dimension variables
Dim adoCon                 \'ADO Connection Object
Dim strCon                \'Holds the Database driver and the path and name of the database
Dim strSQL                 \'Database query sring
Dim strInputTitle             \'Holds the URL Title
Dim strInputURL             \'Holds the URL
Dim strInputDescription         \'Holds the description of the URL
Dim strInputKeywords             \'Holds the keywords for the URL
Dim blnNewURL                \'Set to false if the URL has been entered before
Dim saryDescriptionWord         \'Array to hold each word in the description enetred by the user
Dim intCheckWordLengthLoopCounter    \'Loop counter
Dim intWordLength            \'Holds the length of the word to be checked
Dim blnWordLenthOK            \'Boolean set to False if any words in the description are above 30 characters
Dim intLongestWordLength         \'Holds the number of characters in the longest word entered in the description


\'Error handler (stops the script crashing if there is an error)
On error resume next


\'Read in user deatils from the add URL form
strInputTitle = Request.Form(\"title\")
strInputURL = Request.Form(\"url\")
strInputDescription = Request.Form(\"description\")
strInputKeywords = Request.Form(\"keywords\")


\'Where someones has pressed return in there description replace this with a space
\'as otherwise the last word and first word on the line are seen as one word and may go over the 30 chrarcter limit
strInputDescription = Replace(strInputDescription, vbCrLf, \" \")



\'Split-up each word in the description from the user to check that no word entered is over 30 characters
saryDescriptionWord = Split(Trim(strInputDescription), \" \")
   
\'Initialse the word length variable
blnWordLenthOK = True
   
\'Loop round to check that each word in the description entered by the user is not above the 30 characters
For intCheckWordLengthLoopCounter = 0 To UBound(saryDescriptionWord)
   
    \'Initialise the intWordLength variable with the length of the word to be searched
    intWordLength = Len(saryDescriptionWord(intCheckWordLengthLoopCounter))
   
    \'Get the number of characters in the longest word
    If intWordLength => intLongestWordLength Then
        intLongestWordLength = intWordLength
    End If
       
    \'If the word length to be searched is more than or equal to 30 then set the blnWordLegthOK to false
    If intWordLength => 30 Then
        blnWordLenthOK = False
               
    End If
Next



\'Replace harmful characters in the form elements entered by the user that would cuase an SQL error when writting to the database
strInputTitle = Replace(strInputTitle, \"\'\", \"\'\'\")
strInputURL = Replace(strInputURL, \"\'\", \"\'\'\")
strInputDescription = Replace(strInputDescription, \"\'\", \"\'\'\")
strInputKeywords = Replace(strInputKeywords, \"\'\", \"\'\'\")


\'Check URL doesn\'t already exsist in the database by calling the CheckNewURLDoseNotExsit function (at bottom of script)
blnNewURL = CheckNewURLDoseNotExsit(strInputURL)


\'If the URL exists then update the URL information in the database
If blnNewURL = False Then

    \'If the URL exists then set the strSQL string to update the record in the database for that URL
    strSQL = \"UPDATE tblWebsites SET \"
    strSQL = strSQL & \" Title=\'\" & strInputTitle & \"\'\"
    strSQL = strSQL & \", \" & \"Description=\'\" & strInputDescription & \"\'\"
    strSQL = strSQL & \", \" & \"Keywords=\'\" & strInputKeywords & \"\'\"
    strSQL = strSQL & \", \" & \"Date_Entered=\'\" & Now() & \"\'\"
    strSQL = strSQL & \" WHERE URL =\'\" & strInputURL & \"\';\"

\'Else the URL is new so insert the new details in the Database
Else

    \'Initialise the strSQL string with the SQL statment to insert the new URL in the database
    strSQL = \"INSERT INTO tblWebsites ( Title, URL, Description, Keywords )\"
    strSQL = strSQL & \" VALUES\"
    strSQL = strSQL & \"(\'\" & strInputTitle & \"\'\"
    strSQL = strSQL & \", \'\" & strInputURL & \"\'\"
    strSQL = strSQL & \", \'\" & strInputDescription & \"\'\"
    strSQL = strSQL & \", \'\"  & strInputKeywords & \"\');\"

End If


\'If the user has entered no words over 30 characters then write to database
If blnWordLenthOK = True Then


    \'Write to the database
   
   
    \'Create a connection odject to the database
    Set adoCon = Server.CreateObject(\"ADODB.Connection\")
   
   
    \'Construct a connection string for the database Connection Object
    \'Use the Microsoft Access Driver for the Connection object
    strCon=\"DRIVER={Microsoft Access Driver (*.mdb)}; \"
   
    \'Place in the Connection string the path and the name of the database, using the Server.MapPath method to get the path on the server to the database
    strCon = strCon & \"DBQ=\" & Server.MapPath(\"search_engine\")
   
       
    \'Set an active connection to the Connection object
    adoCon.Open strCon
           
    \'Write to the database
    adoCon.Execute(strSQL)
       
    \'Close Sever Objects
    Set adoCon = Nothing
   
End If


\'Display HTML Message
%>
<HTML>
<HEAD>
<META http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">
<TITLE>Add New URL</TITLE>
 
</head>
<body bgcolor=\"#330099\" text=\"#FFFFFF\" link=\"#66CCFF\" vlink=\"#66CCFF\" alink=\"#FF0000\">
<div align=\"center\"><br>
  <h1>Add URL</h1><br>
  <br>
</div>
<div align=\"center\">
  <%

\'If any of the words in the description are above 30 chracters then disoplay an error message
If blnWordLenthOK = False Then
    Response.Write \"Sorry the URL \" & strInputURL & \" has <b>NOT</b> been added<br>You have used a word in your discription that has \" & intLongestWordLength & \" characters, this is to many!\"
    Response.Write \"<br><br><a href=\"\"java script:history.back(1)\"\" target=\"\"_self\"\">Edit the URL Description Entered</a>\"

\'If the URL has already been entered then display a message asying the URL has been updated
ElseIf  blnNewURL = False Then
    Response.Write \"Thank-you for updating \" & strInputURL & \"<br>The URL entered has been updated\"
    Response.Write \"<br><br><a href=\"\"add_url_form.htm\"\" target=\"\"_self\"\">Add another URL</a>\"

\'Else display that the new URL has been entered into the database
Else
    Response.Write \"Thank-you for entering \" & strInputURL & \"<br>The URL has been entered to the search engine database\"
    Response.Write \"<br><br><a href=\"\"add_url_form.htm\"\" target=\"\"_self\"\">Add another URL</a>\"
End If
%>
<br>
  <br>
  <a href=\"default.htm\" target=\"_self\"> Return to the search engine</a><br>
  <br>
</div>
<div align=\"center\"> <br>
</div>
</body>
</html>
<%



\'Function to check that it is a new URL being entered into the database
Private Function CheckNewURLDoseNotExsit(strInputURL)

    \'Dimension variables
    Dim adoCon         \'ADO Connection Variable
    Dim adoRec         \'ADO Recordset Variable
    Dim strAccessDB     \'Holds the Access Database Name
    Dim strSQL         \'Database query sring
    Dim strCheckURL        \'Holds the name of the URL from the database to be checked

    \'Error handler
    On error resume next
   
    \'Intialise the CheckNewURLDoseNotExsit varible
    CheckNewURLDoseNotExsit = True

    \'Initialise the strAccessDB variable with the name of the Access Database
    strAccessDB = \"search_engine\"
   
       
    \'Create a connection odject to the database
    Set adoCon = Server.CreateObject(\"ADODB.Connection\")
    Set adoRec = Server.CreateObject(\"ADODB.Recordset\")
   
    \'Open connection to the database driver
    adoCon=\"DRIVER={Microsoft Access Driver (*.mdb)};\"
   
    \'Open Connection to database
    adoCon = adoCon & \"DBQ=\" & server.mappath(strAccessDB)
   
   
    \'Initalise the strSQL variable with an SQL statement to get all the URLs from database
    strSQL = \"SELECT URL FROM tblWebsites\"

           
    \'Query the database
    adoRec.Open strSQL, adoCon
       
    \' loop through the records in the database to check the URL does\'t already exist
    \' using a Do While...Loop statement
    Do while not adoRec.EOF
           
              \'Read in the URLs form the database   
              strCheckURL = adoRec(\"URL\")
             
              \'Check a URL entered is not the same as the URL being checked in the database
              If strCheckURL = strInputURL Then
           
            \'If the URL is the same as one in the database then set the Function to False
            CheckNewURLDoseNotExsit = False
       
              End If   
       
        \' Move to the next record
        adoRec.MoveNext
       
    Loop
   
    \'Close Sever Objects
    Set adoCon = Nothing
    Set adoRec = Nothing

End Function

%>

---- add_url_form.htm

<HTML>
<HEAD>
<META http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">
<TITLE>Add New URL</TITLE>


<script  language=\"JavaScript\">
<!-- Hide from older browsers...

//Function to count the number of characters in the description text box
function DescriptionCharCount() {
    document.frmAddURL.countcharacters.value = document.frmAddURL.description.value.length;
}

//Function to check that the form is filled in correctly
function CheckForm () {

    //Check for a URL title
    if (document.frmAddURL.title.value == \"\"){
        alert(\"Please enter the web site title\");
        document.frmAddURL.title.focus();
        return false;
    }
   
    //Check for a URL address
    if (document.frmAddURL.url.value == \"\"){
        alert(\"Please enter a URL address\");
        document.frmAddURL.url.focus();
        return false;
    }
   
    //Check for a URL address after the http: bit
    if (document.frmAddURL.url.value == \"http://\"){
        alert(\"Please enter a URL address\");
        document.frmAddURL.url.focus();
        return false;
    }
       
    //Check for keywords
    if (document.frmAddURL.keywords.value == \"\"){
        alert(\"Please enter some keywords\");
        document.frmAddURL.keywords.focus();
        return false;
    }
   
    //Check for a description
    if (document.frmAddURL.description.value == \"\"){
        alert(\"Please enter a description for the site\");
        document.frmAddURL.description.focus();
        return false;
    }   
   
    //Check the description length before submiting the form   
    if (document.frmAddURL.description.value.length >= 200){
        alert(\"Sorry, you have gone over 200 characters in your description\\nPlease shorten your description\");
        document.frmAddURL.description.focus();
        return false;
    }
   
    //Check for HTML tags before submitting the form   
    for (var count = 0; count <= 3; ++count){
        if ((document.frmAddURL.elements[count].value.indexOf(\"<\", 0) >= 0) && (document.frmAddURL.elements[count].value.indexOf(\">\", 0) >= 0)){
            alert(\"Sorry, HTML tags are not permitted\");
            document.frmAddURL.elements[count].focus();
            return false;
        }           
    }   
   
    return true
}
// -->
</script>

</head>
<body bgcolor=\"#330099\" text=\"#FFFFFF\" link=\"#66CCFF\" vlink=\"#66CCFF\" alink=\"#FF0000\">
<h1 align=\"center\">Add New URL</h1>
<div align=\"center\"><a href=\"default.htm\" target=\"_self\">Return to the search
  engine</a><br>
  <br>
  HTML tags are not permitted</div>
<form method=post name=\"frmAddURL\" action=\"add_URL.asp\" onSubmit=\"return CheckForm();\">
  <table width=\"90%\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\" height=\"226\" bgcolor=\"#333399\">
    <tr>
      <td height=\"257\">
        <table width=\"100%\" border=\"0\" align=\"center\" class=\"normal\" height=\"166\">
          <tr align=\"left\">
            <td colspan=\"2\" class=\"arial_sm2\" height=\"30\">*Indicates required
              fields</td>
          </tr>
          <tr class=\"arial\">
            <td align=\"right\" width=\"20%\" height=\"14\" class=\"arial\">Sit Title*:
            </td>
            <td height=\"14\">
              <input type=\"text\" name=\"title\" size=\"45\" maxlength=\"50\" >
            </td>
          </tr>
          <tr class=\"arial\">
            <td align=\"right\" width=\"20%\" class=\"arial\" height=\"12\">URL*:</td>
            <td height=\"12\">
              <input type=\"text\" name=\"url\" size=\"45\" maxlength=\"80\" value=\"http://\">
            </td>
          </tr>
          <tr class=\"arial\">
            <td align=\"right\" width=\"20%\" class=\"arial\" height=\"12\">Keywords*:</td>
            <td height=\"12\">
              <input type=\"text\" name=\"keywords\" size=\"45\" maxlength=\"200\" >
            </td>
          </tr>
          <tr class=\"arial\">
            <td align=\"right\" width=\"20%\" class=\"arial\" height=\"2\" valign=\"top\">Description*:<br>
              <font face=\"Times New Roman, Times, serif\" size=\"2\">(max. characters
              200)</font></td>
            <td height=\"2\" valign=\"top\">
              <textarea name=\"description\" cols=\"40\" rows=\"5\" wrap=\"PHYSICAL\" onChange=\"DescriptionCharCount();\"></textarea>
            </td>
          </tr>
          <tr>
            <td align=\"right\" height=\"11\" width=\"20%\" class=\"arial\">Character
              Count:</td>
            <td height=\"11\">
              <input size=\"3\" value=\"0\" name=\"countcharacters\" maxlength=\"3\">
              &nbsp;
              <input onClick=\"DescriptionCharCount();\" type=\"button\" value=\"Count\" name=\"Count\">
            </td>
          </tr>
          <tr>
            <td valign=\"top\" align=\"right\" height=\"7\" width=\"20%\" class=\"arial\">&nbsp;
            </td>
            <td height=\"7\">
              <p>
                <input type=\"reset\" name=\"Reset\" value=\"Clear Form\">
                <input type=\"submit\" name=\"Submit\" value=\"Add URL to Search Engine\">
              </p>
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
</form>
<div align=\"center\"><br>
  <a href=\"http://www.surf-net.co.uk\" target=\"_blank\"><img src=\"surf-net_logo.gif\" width=\"88\" height=\"31\" border=\"0\" alt=\"Surf-net\"></a><br>
</div>
</body>
</html>

Avatar billede nuno Nybegynder
26. maj 2001 - 11:33 #6
der er jo on error resume next på det - prøv at fjerne den og kør scriptet igen - så kan du se hvilket linie nummer den giver fejlen i.

/nuno
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester