#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0

    Posting forms using asp


    Hi all,

    I have a form as shown below

    Code:
    <html>
    <head>
    <title>Form to Database</title>
    </head>
    <body>
    <!-- comment - start the HTML form and
    use a HTML table for formatting-->
    <form name="form1" action="add_to_database.asp" method="post">
    <div align="center">
    <table width="80%" border="0">
    <tr>
    <td>Name :</td>
    <td><input type="text" name="name"></td>
    </tr>
    <tr>
    <td>Email :</td>
    <td> <input type="text" name="email"></td>
    </tr>
    <tr>
    <td>Comments :</td>
    <td><textarea name="comments"></textarea></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td><input type="submit" value="submit
    details" name="submit"></td>
    </tr>
    </table>
    </div>
    </form>
    <!-- end the HTML form-->
    </body>
    </html>
    using asp named add_to_database.asp as shown below

    Code:
    <%@ Language="VBScript" %>
    <% Option Explicit %>
    <html>
    <head>
    <title>Form to database</title>
    </head>
    <body>
    <%
    'declare your variables
    Dim name, email, comments
    Dim sConnString, connection, sSQL
    'Receiving values from Form, assign the values entered to 'variables
    name = Request.Form("name")
    email = Request.Form("email")
    comments =Request.Form("comments")
    
    'declare SQL statement that will query the database
    sSQL = "INSERT into users_tbl (name, email, comments) values
    ('" & _name & "', '" & email & "', '" & comments & "')"
    'define the connection string, specify database
    'driver and the location of database
    sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=" & Server.MapPath("Users.mdb")
    
    'create an ADO connection object
    Set connection = Server.CreateObject("ADODB.Connection")
    
    'Open the connection to the database
    connection.Open(sConnString)
    
    'execute the SQL
    connection.execute(sSQL)
    
    response.write "The form information was inserted successfully."
    'Done. Close the connection object
    connection.Close
    Set connection = Nothing
    %>
    </body>
    </html>
    i also created a database called users.mdb

    Each time i click the submit button, it does not post to the database, it only load the asp page.

    Please can any one advice
  2. #2
  3. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,439
    Rep Power
    4539
    what do you mean by "only loads the asp page"? If you are seeing the asp code in your browser make sure your web server supports classic asp and is properly configured.
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0
    hi, Thanks for your response.
    pls this is not a class assignment. I am new to web designin and Just been curious. The problem I am having now is that after installing classic asp with with iis. I still can't get it to work. I keep having the 404 error when I do http://localhost.

    I have disabled skype on port 80, delete browser history and cache, have also bind the port 80 to the localhost using the inetmgr, have also ensure I have the line ''127.0.0.1 localhost" in my ..\etc\host file but still to no avail.

    Pls can anyone help
  6. #4
  7. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,439
    Rep Power
    4539
    From your sketchy description it sounds like your IIS isn't properly configured. I haven't used IIS since IIS5 but there are lots of online resources to hep you get your web server working properly.
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester

IMN logo majestic logo threadwatch logo seochat tools logo