SitePoint Sponsor

User Tag List

Results 1 to 1 of 1
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2004
    Location
    Manchester
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form validate against MySQL database

    I want a user to be able to enter a discount word that then returns a discount value from a MySQL database but I want to validate the entry so that it will return an alert if the value entered is not in the database.
    At present if only validates against one entry but obviously can't have the word in the javascript for all to see.

    Could someone look at my code and advise what I need to do..

    The Form Page
    Code:
    <html>
    <head>
    <script LANGUAGE="JavaScript">
     function form_validatordiscount(theForm) {
      if(theForm.searchstring1.value != "a1" ) {
        alert("Please enter a valid string!");
        theForm.searchstring1.focus();
        return(false);
      }
      return (true);
    }
    </script>
    </head>
    <body>
    <form onSubmit="return form_validatordiscount(this)" method="post" action="result2.asp">
      <tr> 
        <td> <div align="left"></div>
     <input type=text name="searchstring1" value="" size=9>
    <input name="submit" type="submit" class="button" value=" Discount ">
      </td>
      </tr>  </FORM>
    </body>
    </html>
    The result page

    Code:
    <html>
    <head>
    </head>
    <body>
    <%
    search1=request.form("searchstring1")
    Set conn = Server.CreateObject("ADODB.Connection")
    conn.Open "DRIVER={MySQL ODBC 3.51 Driver};server=xxxxxxxx"
    set rs=conn.execute("SELECT * FROM discount where discountword = '" & search1 & "'")
    %>
    Results for <%=search1%> = <% =rs("discountvalue") %>
    Boy, you have a <% =rs("discountammount") %> Discount
    </body>
    </html>
    Last edited by Northernladuk; Sep 20, 2004 at 17:35.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •