www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 21

Thread: The information from the form on my website won't add to my database.

  1. #1
    Join Date
    Nov 2004
    Posts
    29

    The information from the form on my website won't add to my database.

    I have this problem and don't know what it is....can anyone help. None of the information from the form that is typed in is being added to the database. and i dn't know why. The Database is opened, and thje source is set in the include.asp page.
    Code:
    <link rel="stylesheet" type="text/css" href="styles.css"/>
    <!-- #include file = "Include.asp" -->
    <!-- #include file = "Adovbs.inc" -->
    <html>
    <HEAD>
    <title>
    </title>
    </HEAD>
    <body>
    <FORM ACTION="database.htm">
    <INPUT TYPE = SUBMIT VALUE="Return to Database Page">
    </FORM>
    <%
    Phone=request.form("Phone")
    FirstName=request.form("FirstName")
    LastName=request.form("LastName")
    Address=request.form("Address")
    city=request.form("city")
    province=request.form("province")
    PostalCode=request.form("PostalCode")
    %>
    
    <%
    strQuery = "Insert into Contacts (Phone, FirstName, LastName, Address, City, province, PostalCode) values ('"& Phone &"', '"& FirstName &"', '"& LastName &"','"& Address &"','"& city &"', '"& province &"', '"& PostalCode &"')"
    
    oC.open cs
    oCM.ActiveConnection = oC
    oCM.CommandText = strQuery
    oCM.CommandType = adCmdText
    oCM.Execute
    response.write(strQuery)
    oC.close
    set oC=nothing
    %>
    <p> The Current Records are in the Database:</p>
    <br>
    <% oRS.open "Select * from Contacts", cs %>
    
    <table border = "0" width="100%">
    <tr><td>Phone</td>
        <td>First Name</td>
        <td>Last Name</td>
        <td>Address</td>
        <td>City</td>
        <td>Province</td>
        <td>Postal</td>
    <tr>
    <% do while not oRS.EOF %>
    <tr>
    	<td><% = oRS("Phone") %></td>
    	<td><% = oRS("FirstName") %></td>
    	<td><% = oRS("LastName") %></td>
    	<td><% = oRS("Address") %></td>
    	<td><% = oRS("City") %></td>
    	<td><% = oRS("province") %></td>
    	<td><% = oRS("PostalCode") %></td>
    </tr>
    <% oRS.movenext
    loop
    
    oRS.close
    set oRS = nothing
    %>
    </table>
    
    </body>
    </html>

  2. #2
    Join Date
    Feb 2003
    Posts
    2,745
    do you get any errors? if so what do they say. what do you get on this line:

    response.write(strQuery)

    Which, by the way, should be:

    response.write strQuery

  3. #3
    Join Date
    Nov 2004
    Posts
    29
    i don't get any errors. Im writing the code out of notepad and then just changing the code to a html file.

  4. #4
    Join Date
    Jun 2004
    Location
    Kansas City, MO
    Posts
    1,607
    I dont do updates like this but this might be it.
    Try this

    oCM.Execute(strQuery)

    you currently have

    oCM.Execute

    I think you have to supply it a variable (sql query) to execute.

    also put this line at the top of you page.

    <%option explicit%>

    This would of made it error out. With out this your page will not error out.
    You will have to declare all variables but this is good programming practice.

  5. #5
    Join Date
    Feb 2003
    Posts
    2,745
    Make it an asp file, not an html file.

    oCM.Execute is the correct syntax. This is a command object, not a connection object.

  6. #6
    Join Date
    Nov 2004
    Posts
    29
    im confused.

    the code above is in asp. The database connects to the asp page after the button is clicked.

  7. #7
    Join Date
    Feb 2003
    Posts
    2,745
    writing the code out of notepad and then just changing the code to a html file.
    Are you saving it with an .asp extension?

    Did you do a Response.Write strQuery? What did it write out?

    Make sure there are no "On Error Resume Next" in the file, or the include file.

    What does the web browser show after the form is posted?

    Right-click and View Source of the web page. Scroll to the last line. Any errors there, that maybe dont show up in the displayed html?

  8. #8
    Join Date
    Jun 2004
    Location
    Kansas City, MO
    Posts
    1,607
    Im writing the code out of notepad and then just changing the code to a html file.
    russell is saying you need to save it with a .asp extension and not a .htm extension.


    Damn russell your fast, i looked at it typed it and then i saw your post, lol.

    damn you posted another reply while i was editing this one, lol
    Last edited by lmf232s; 11-12-2004 at 02:43 PM.

  9. #9
    Join Date
    Feb 2003
    Posts
    2,745
    note that if you are saving it with an HTM or HTML extension, none of your asp will be parsed.

  10. #10
    Join Date
    Feb 2003
    Posts
    2,745
    Hmmm lmf, I wonder if you are typing right now...

  11. #11
    Join Date
    Nov 2004
    Posts
    29
    There is an include.asp which has the following, which was typed out using notepad
    Code:
    <%
    dim drv, dbq, cs, oC, oRS, oCM
    drv = "Provider=Microsoft.Jet.OLEDB.4.0;"
    dbq = "Data Source=C:\WINDOWS\Desktop\html\htmldatabase.mdb"
    cs = drv & dbq
    set oC = server.createobject("ADODB.connection")
    set oRS = server.createobject("ADODB.recordset")
    set oCM = server.createobject("ADODB.Command")
    %>
    the code that is pasted above(that i posted the first time) has the file extension .asp on it. )its named "addrecord.asp"

    the website, or html document im using to get the information from is the database.htm and its code is as follows:
    Code:
    <html>
    <head>
    <link rel="stylesheet" type="text/css" href="styles.css">
    <!--setting page background color and text color-->
    </head>
    <body>
    <FORM ACTION="addrecord.asp" method="post">
    <font color = white">
    Phone<input type="text" name="Phone" size="7">
    <p>
    First Name <input type="text" name="FirstName" size="15">
    <p>
    Last Name <input type="text" name="LastName" size="15">
    <p>
    Address <input type="text" name="Address" size="20">
    <p>
    City <input type="text" name="city" size="15">
    <p>
    Province <input type="text" name="province" size="15">
    <p>
    Postal Code <input type="text" name="PostalCode" size="7">
    <input type="submit" value="add">
    <input type="reset" value="reset">
    </font>
    </FORM>
    </body>
    </html>
    I do not get any errors, the only thing is that the information i input from the database page, will not write to the database i created.

  12. #12
    Join Date
    Feb 2003
    Posts
    2,745
    ok, your code with a couple of debugging statements:
    Code:
    <link rel="stylesheet" type="text/css" href="styles.css"/>
    <!-- #include file = "Include.asp" -->
    <!-- #include file = "Adovbs.inc" -->
    <html>
    <HEAD>
    <title>
    </title>
    </HEAD>
    <body>
    <FORM ACTION="database.htm">
    <INPUT TYPE = SUBMIT VALUE="Return to Database Page">
    </FORM>
    <%
    Phone=request.form("Phone")
    FirstName=request.form("FirstName")
    LastName=request.form("LastName")
    Address=request.form("Address")
    city=request.form("city")
    province=request.form("province")
    PostalCode=request.form("PostalCode")
    
    For each f in Request.Form
       Response.Write f & " " & Request.Form(f) & "<br>"
    Next
    
    %>
    
    <%
    strQuery = "Insert into Contacts (Phone, FirstName, LastName, Address, City, province, PostalCode) values ('"& Phone &"', '"& FirstName &"', '"& LastName &"','"& Address &"','"& city &"', '"& province &"', '"& PostalCode &"')"
    
    oC.open cs
    oCM.ActiveConnection = oC
    oCM.CommandText = strQuery
    oCM.CommandType = adCmdText
    oCM.Execute
    'response.write(strQuery)
    
    Response.Write strQuery
    
    oC.close
    set oC=nothing
    %>
    <p> The Current Records are in the Database:</p>
    <br>
    <% oRS.open "Select * from Contacts", cs %>
    
    <table border = "0" width="100%">
    <tr><td>Phone</td>
        <td>First Name</td>
        <td>Last Name</td>
        <td>Address</td>
        <td>City</td>
        <td>Province</td>
        <td>Postal</td>
    <tr>
    <% do while not oRS.EOF %>
    <tr>
    	<td><% = oRS("Phone") %></td>
    	<td><% = oRS("FirstName") %></td>
    	<td><% = oRS("LastName") %></td>
    	<td><% = oRS("Address") %></td>
    	<td><% = oRS("City") %></td>
    	<td><% = oRS("province") %></td>
    	<td><% = oRS("PostalCode") %></td>
    </tr>
    <% oRS.movenext
    loop
    
    oRS.close
    set oRS = nothing
    %>
    </table>
    
    </body>
    </html>
    What do you get when you run it now?

  13. #13
    Join Date
    Nov 2004
    Posts
    29
    Originally posted by russell
    ok, your code with a couple of debugging statements:
    Code:
    <link rel="stylesheet" type="text/css" href="styles.css"/>
    <!-- #include file = "Include.asp" -->
    <!-- #include file = "Adovbs.inc" -->
    <html>
    <HEAD>
    <title>
    </title>
    </HEAD>
    <body>
    <FORM ACTION="database.htm">
    <INPUT TYPE = SUBMIT VALUE="Return to Database Page">
    </FORM>
    <%
    Phone=request.form("Phone")
    FirstName=request.form("FirstName")
    LastName=request.form("LastName")
    Address=request.form("Address")
    city=request.form("city")
    province=request.form("province")
    PostalCode=request.form("PostalCode")
    
    For each f in Request.Form
       Response.Write f & " " & Request.Form(f) & "<br>"
    Next
    
    %>
    
    <%
    strQuery = "Insert into Contacts (Phone, FirstName, LastName, Address, City, province, PostalCode) values ('"& Phone &"', '"& FirstName &"', '"& LastName &"','"& Address &"','"& city &"', '"& province &"', '"& PostalCode &"')"
    
    oC.open cs
    oCM.ActiveConnection = oC
    oCM.CommandText = strQuery
    oCM.CommandType = adCmdText
    oCM.Execute
    'response.write(strQuery)
    
    Response.Write strQuery
    
    oC.close
    set oC=nothing
    %>
    <p> The Current Records are in the Database:</p>
    <br>
    <% oRS.open "Select * from Contacts", cs %>
    
    <table border = "0" width="100%">
    <tr><td>Phone</td>
        <td>First Name</td>
        <td>Last Name</td>
        <td>Address</td>
        <td>City</td>
        <td>Province</td>
        <td>Postal</td>
    <tr>
    <% do while not oRS.EOF %>
    <tr>
    	<td><% = oRS("Phone") %></td>
    	<td><% = oRS("FirstName") %></td>
    	<td><% = oRS("LastName") %></td>
    	<td><% = oRS("Address") %></td>
    	<td><% = oRS("City") %></td>
    	<td><% = oRS("province") %></td>
    	<td><% = oRS("PostalCode") %></td>
    </tr>
    <% oRS.movenext
    loop
    
    oRS.close
    set oRS = nothing
    %>
    </table>
    
    </body>
    </html>
    What do you get when you run it now?
    i don't understand that for loop....

    and i will let you onow what i get when i try this later.
    appreciate your help tho. thanks.

  14. #14
    Join Date
    Jan 2004
    Location
    Melbourne, Australia
    Posts
    5,298
    It will juest print out a list of the name/value pairs in the Form collection.

  15. #15
    Join Date
    Nov 2004
    Posts
    29

    Angry

    edit: i just add whats in red to my code, correct?

    i added this to my asp page. and it still won't write to the database...or come up in the table at the bottom.
    Last edited by Ennis; 11-12-2004 at 09:25 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles