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
Problem inserting data to database
Collapse
X
-
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.
byeComment
-
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
-
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
-
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"%>?Originally posted by bseakganoI 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
JaredComment
-
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 thisComment
-
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?Originally posted by bseakganoJared ,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
JaredComment
-
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?Originally posted by jhardmanIt 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
JaredComment
-
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 byeComment
-
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 lotComment
-
That may be your problem!Originally posted by bseakganoAm 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
This is the ASP forum, for ASP.NET questions, please post in the .NET forum.
JaredComment
Comment