Problem inserting data to database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bseakgano
    New Member
    • Mar 2007
    • 12

    #16
    I just got text the Box Which I was suppoused to key in some words. I saved it with ASP and HTML to try to fined if they will be any defference. And it show the same error i was talking about last time. a mixure of words and codes. you > just on in top like a stamp

    Comment

    • subashini Thiyagarajan
      New Member
      • Dec 2006
      • 218

      #17
      Hi bseakgano,

      It is very difficult to understand your problem because of the way you presented.

      ok come to the point.u want to insert a record to the database right,

      i ve seen your code u have used if statement where is the else part firtst.since there is nothing(i mean any field left blank) it will not insert any record to the database your codings means that.

      so please restrict the input information first with regularities.

      i'll write some simple codings to u pls make use of it.i have done using access database i think u r using SQL ,just change the connection setup i mean provider name try to amend your code as the below

      just try with the below code make atleast one record to sit in the database first then u amend as per your requirement

      create one table of the following fields

      name
      age
      comment(u choose any thing)

      Code:
      <html><body>
      
      <%
      
      If Request.Form("ClearButton") = "Clear Form" Then
          name = ""
        age = ""
        comment =""
        End If
      
      If Request.Form("AddButton") = "Add Record" Then
      	date = Now()
      	name = Request.Form("name")
        age = Request.Form("age")
        comment = Request.Form("comment")
      
        Valid = True
      
        ' -- Check name for blanks
      If name = "" Then
          Msg1 = "Name is required."
          Valid = False
        End If
       ' -- Check age for blanks
        If age = "" Then
          Msg2 = "Select your age."
          Valid = False
        End If
      
      ' -- Check comment for blanks
        If comment = "" Then
          Msg3 = "write some comment"
          Valid = False
        End If
       
       
        '-- Write new record to table
         If Valid = True Then
         Set CNObj = Server.CreateObject("ADODB.Connection")
          'write your driver name instead of access driver
      	CNObj.Open "DBQ=C:\Inetpub\wwwroot\manage\ivr.mdb;DRIVER=Microsoft Access Driver (*.mdb)"
          Set RSAdd = Server.CreateObject("ADODB.Recordset")
          SQL = "SELECT * FROM tablename WHERE Null"
          RSAdd.Open SQL, CNObj, 1,3,1
      	
          RSAdd.AddNew
      	RSAdd.Fields("name") = name
      	RSAdd.Fields("age") = age
      	RSAdd.Fields("comment") = comment
          
      	RSAdd.Update
      		
       Msg = "Record has inserted in table"
          RSAdd.Close
          CNObj.Close
        
        End If
      
      End If
      %>
      
      
      <html>
      <body>
      
      <form action="samepage.asp" method="post">
        <table border="1" align="center">
      <tr>
        <th>Date/Time:</th>
        <td><%=Now()%></td>
      </tr>
      <tr>
        <th>Name: </th>
        <td><input name="Itemadd3" type="text" size="50" maxlength="50" value="<%=Itemadd3%>">
            <%=Msg1%></td>
      </tr>
      <tr>
        <th>Age:</th> <td> <input type="text" name="age"> <%=Msg2%></td>
      </tr> 
      <tr>
        <th>Comment: </th>
        <td><label>
          <textarea name="Itempair"><%=Itempair%></textarea><%=Msg3%>
        </label></td>
      </tr>
      </table>
      <br>
      <center>
      <input type="submit" name="AddButton" value="Add Record">
      <input type="submit" name="ClearButton" value="Clear Form"><%=Msg%>
      </center>
      </form>
      
      </body>
      </html>


      Try with the above code and let me know.

      bye

      Comment

      • bseakgano
        New Member
        • Mar 2007
        • 12

        #18
        Now the Code look to have problem with <form action="samepag e.asp" method="post"> it triad not to change so that I can know . I saved it with HTML . It shows me another Window Saying C:\Inetpub\wwwr oot\samepage.as p which is it want a an asp file . though I have saved them both in one page . Please you help with an asp file.

        Comment

        • subashini Thiyagarajan
          New Member
          • Dec 2006
          • 218

          #19
          Dear,

          don't separate it as HTML and ASP .

          u can save any codings with .html also and .asp also no differnences..o k.

          now copy paste the code which i sent to u and save that file with

          filename.asp

          then go to form tag and amend

          <form action="filenam e">

          so that it will execute and refresh in the same page.

          reply me with your problems now.

          Comment

          • jhardman
            Recognized Expert Specialist
            • Jan 2007
            • 3405

            #20
            Originally posted by bseakgano
            I just got text the Box Which I was suppoused to key in some words. I saved it with ASP and HTML to try to fined if they will be any defference. And it show the same error i was talking about last time. a mixure of words and codes. you > just on in top like a stamp
            You know what? I think your server is not set up to handle scripts. Itried this in my server (just before it crashed, sorry you can't see) and it worked fine. Can you handle very simple scripts like <%="Hello world"%>?

            Jared

            Comment

            • bseakgano
              New Member
              • Mar 2007
              • 12

              #21
              It is like I am calling the code . when I click the button , hoping that it will be inserting information into the Database , I just get the code . But when I save the whole code into one thing . It just take me to the weather information. It is strange . I asked myself a question like which code here deals with weather but I found none. Hope I will get a message like you code had been inserted into the database .


              Jared ,When I try to right something like hello . it just do as that , hello get displayed . But the problem arise when I try to link it with SQL. OR is the installation of ASP I don’t know . I really want want to do this

              Comment

              • jhardman
                Recognized Expert Specialist
                • Jan 2007
                • 3405

                #22
                Originally posted by bseakgano
                Jared ,When I try to right something like hello . it just do as that , hello get displayed . But the problem arise when I try to link it with SQL. OR is the installation of ASP I don’t know . I really want want to do this
                It doesn't make sense to me that the script should break when it encounters the SQL code. It is as if your server stops handling the scripts. At very least it should give an error message. Which server are you using?

                Jared

                Comment

                • jhardman
                  Recognized Expert Specialist
                  • Jan 2007
                  • 3405

                  #23
                  Originally posted by jhardman
                  It doesn't make sense to me that the script should break when it encounters the SQL code. It is as if your server stops handling the scripts. At very least it should give an error message. Which server are you using?

                  Jared
                  Sorry, I read back and saw that you did answer that. It still doesn't make sense. It sounds like it is a problem with how your IIS is configured, but all I can do is scratch my head at this point. Can someone else reading this confirm that the codes we posted work? I tested it, but then my domain registration ran out, so I can't show how it works. Subashini, did you test this?

                  Jared

                  Comment

                  • subashini Thiyagarajan
                    New Member
                    • Dec 2006
                    • 218

                    #24
                    Hi,
                    I am really confused by the way u people are communicating.
                    Let her first draft a clear picture about her problems.then we can start giving suggestions to her.

                    I send the codings with simple explanation,ple ase read it properly if u do copy paste nothing will work.try to understand line by line then to implement.where ever the file name required please provide it then come to me.

                    i 'll really help u.
                    ok bye

                    Comment

                    • bseakgano
                      New Member
                      • Mar 2007
                      • 12

                      #25
                      Am using VB.Net though it is my first time to use it . I just want to insert , delete , seach, update pictures into database, I want to using vb.net and forms(ASP) to insert pictures into SQL. Please help with 2 to 3 lines. I mean how SQL should look, Vb.net should (connect) look, forms should (connect) look. Believe that three line of codes from each can help a lot

                      Comment

                      • jhardman
                        Recognized Expert Specialist
                        • Jan 2007
                        • 3405

                        #26
                        Originally posted by bseakgano
                        Am using VB.Net though it is my first time to use it . I just want to insert , delete , seach, update pictures into database, I want to using vb.net and forms(ASP) to insert pictures into SQL. Please help with 2 to 3 lines. I mean how SQL should look, Vb.net should (connect) look, forms should (connect) look. Believe that three line of codes from each can help a lot
                        That may be your problem!

                        This is the ASP forum, for ASP.NET questions, please post in the .NET forum.

                        Jared

                        Comment

                        Working...