Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

Problem inserting data to database

Question posted by: bseakgano (Newbie) on March 8th, 2007 09:26 AM
I have developed a intranet . Using HTML , SQL and ASP . I have created a table with SQL is just fine . And design a form is just looks fine to me . But when I try to insert Data into the SQL I just have the Error . The Error appears when I press submit button . But when i just call it using this url http://10.164.1.86/lala.asp . It produce the massege i want it to produce after inserting the information. Hope you can help . My Code looks this one here .


Code: ( text )
  1. <%
  2.  
  3. Catergory = Trim(Request.Form("registry"))
  4. If Catergory= "Title" then
  5. Title = Trim(Request.Form("Title"))
  6. Author = Trim(Request.Form("Author"))
  7. ISBN = Trim(Request.Form("ISBN"))
  8. Publisher= Trim (Request.Form("Publisher"))
  9. Place_of_Publication= Trim(Request.Form("Place of Publication"))
  10. Year=Trim(Request.Form("Year"))
  11. Collation=Trim(Request.Form("Collation"))
  12. Shelf_Number=Trim(Request.Form("Shelf Number"))
  13.  
  14. If Title <>"" and Author <>"" and ISBN <>"" and Publisher <>"" and Place_of_Publication <>"" and Year <>"" and Collation <>"" and Shelf_Number<>"" Then
  15.  
  16. %>
  17.  
  18. MyStatement = "Insert into Book_files Set Values
  19. Title='"&Title&"',Author='"&Author&"', ISBN='"&ISBN&"',Publisher='"&Publisher& "',Place_of_Publication='"& PlaceofPublication&"',Year='"&Year&"',Collation='"& Collation&"',Shelf_Number='"&ShelfNumber&"'"
  20.  
  21. <%
  22.  
  23. Set Con = Server.CreateObject("ADODB.Conection")
  24. Con.Open "PROVIDER=SQLOLEDB;DATA SOURCE=master;UID=sa;PWD=sa;DATABASE=Book_files"
  25.  
  26. Con.Execute MyStatement
  27.  
  28. End IF
  29. End IF
  30.  
  31.  
  32.  
  33.  
  34.  
  35. %>
  36.  
  37. <Html>
  38. <Head><Title>Insert Data</Title></Head>
  39. <Body>
  40. <Form Method="POST" action.asp? /registry.html><Head> <Center> <Font Color="Brown" Size=11 Face="Comic Sans Ms">
  41. Confirmation Page </Font> </Center>
  42.  
  43. <Body BGColor="Yellow">
  44. <Br><Br>
  45.  
  46. <%
  47.  
  48.  
  49. Response.Write(" Your Value Has Been Successfully Inserted In The Table!")
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57. %>
  58.  
  59.  
  60. </Body>
  61.  
  62. </Html>
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
jhardman's Avatar
jhardman
Moderator
2,171 Posts
March 8th, 2007
05:10 PM
#2

Re: Problem inserting data to database
Your code looks OK to me. You get the satisfactory response when you just go to the web page because the db connection is within an if...then statement, so just browsing to that page skips that part of the code.

What error are you getting? There might be a very simple explanation. I'm not sure it would help, but I'm willing to show you how I tend to code this, I write my insert lines a bit differently. I'm sure there's not a right way, but trying it differently couldn't hurt.

Jared

Reply
hini's Avatar
hini
Newbie
19 Posts
March 9th, 2007
12:22 AM
#3

Re: Problem inserting data to database
What does this line mean ?
Form Method="POST" action.asp? /registry.html

Reply
bseakgano's Avatar
bseakgano
Newbie
12 Posts
March 9th, 2007
05:18 AM
#4

Re: Problem inserting data to database
Hello there

When I execute it , Hoping it will show me that the result is inserted into the database , It just show the code of asp instead of confirmation massage . Like you values are inserted in the database . I had been trying this for a long time now . Can you Please try it and tell me it did work.

Reply
bseakgano's Avatar
bseakgano
Newbie
12 Posts
March 9th, 2007
05:19 AM
#5

Re: Problem inserting data to database
When I execute it , Hoping it will show me that the result is inserted into the database , It just show the code of asp instead of confirmation massage . Like you values are inserted in the database . I had been trying this for a long time now . Can you Please try it and tell me it did work.

Reply
bseakgano's Avatar
bseakgano
Newbie
12 Posts
March 9th, 2007
05:23 AM
#6

Re: Problem inserting data to database
This line is used to insert information into the database. It is used to call the parent registry with it. Or I use it to link the side.
Form Method="POST" action.asp? /registry.html[/QUOTE]

Reply
hini's Avatar
hini
Newbie
19 Posts
March 9th, 2007
04:28 PM
#7

Re: Problem inserting data to database
this line is outside the script :

MyStatement = "Insert into Book_files Set Values
Title='"&Title&"',Author='"&Author&"', ISBN='"&ISBN&"',Publisher='"&Publisher&"',Place_of_Publication='"
&PlaceofPublication&"',Year='"&Year&"',Collation='"&Collation&"',Shelf_Number='"&ShelfNumber&"'"


it must be inside the <% %> signs.

Reply
jhardman's Avatar
jhardman
Moderator
2,171 Posts
March 9th, 2007
05:12 PM
#8

Re: Problem inserting data to database
Quote:
Originally Posted by hini
What does this line mean ?
Form Method="POST" action.asp? /registry.html

Good catch, hini, I didn't even notice.

The line should be more like:
Code: ( text )
  1. <Form Method="POST" action="/registry.html">


This could definitely be the problem. Although I'm not sure an HTML page will do anything to interpret the form data. What is the name of the page that handles the form?

Jared

Reply
r035198x's Avatar
r035198x
Administrator
10,647 Posts
March 10th, 2007
07:05 AM
#9

Re: Problem inserting data to database
Guys, let's make it a point to always wrap our code with code tags.

@OP Next time please try to choose a title that best describes your problem. I have just renamed your thread.

Reply
bseakgano's Avatar
bseakgano
Newbie
12 Posts
March 13th, 2007
12:36 PM
#10

Re: Problem inserting data to database
Can you please modify this code if possible . I have months now trying to insert data with this codes . When ever I try to execute this I get an error . I want to insert data into SQL with this codes . If I have skipped a line please let me know. I have tried to search from this site , hoping that someone had the same problems . but theirs was not responded . Now I don’t know what to do. Please help .







Code: ( text )
  1. <A Href="library.Html" Target="ThirdPartition"><Font Face="Garamond" Size="1">HOME</Font></A><br></br>
  2.  
  3.  
  4.  
  5.  
  6. <html>
  7.  
  8.  
  9. <Head> <U> <Center><Font Color="Red" Face="Garamond" Size=11> Registration Book</Font> </Center> </U>
  10. <Title> Registration Page </Title>
  11. </Head>
  12. <Body Bgcolor="Pink">
  13. <Form Method="Post" Action="lala.asp?">
  14. <Br> <Br>
  15. <B>Title:</B> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<Input Type="Text" Name="Title">
  16. <Br> <Br>
  17. <B>Author:</B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<Input Type="Text" Author="Author">
  18. <Br> <Br>
  19. <B>ISBN/ISSN     :</B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<Input Type="Text" ISBN/ISSN="ISBN/ISSN">
  20. <Br> <Br>
  21. <B>Publisher:</B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<Input Type="Text" Name="Publisher"><Br> <Br>
  22. <B>Place Of Publication:</B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<Input Type="Text" Place Of Publication="Place Of Publication"><Br> <Br>
  23. <B>Year:</B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<Input Type="Text" Year="Year">
  24.  
  25. <br></br>
  26. <B>Collation:</B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<Input Type="Text" Collation="Collation">
  27.  
  28. <Br> <Br>
  29. <B>Shelf Number  :</B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<Input Type="Text" Shelf Number="Shelf Number">
  30. <Br> <Br>
  31.  
  32. <Br> <Br>
  33. <Center><Input Type="Submit" Style="Font-Family:Monotype Corsiva;Color:Yellow;Font-Size:22;Font-Weight:Bold;Background:Brown" Value="Submit"></Center>
  34. </Form>
  35. </Body>
  36. </Html>
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51. <%
  52. registry=Trim(Request.Form("registry"))
  53. Catergory = Trim(Request.Form("registry"))
  54. If Catergory= "Title" then
  55. Title = Trim(Request.Form("Title"))
  56. Author = Trim(Request.Form("Author"))
  57. ISBN = Trim(Request.Form("ISBN"))
  58. Publisher= Trim (Request.Form("Publisher"))
  59. Place_of_Publication= Trim(Request.Form("Place of Publication"))
  60. Year=Trim(Request.Form("Year"))
  61. Collation=Trim(Request.Form("Collation"))
  62. Shelf_Number=Trim(Request.Form("Shelf Number"))
  63.  
  64. If Title <>"" and Author <>"" and ISBN <>"" and Publisher <>"" and Place_of_Publication <>"" and Year <>"" and Collation <>"" and Shelf_Number<>"" Then
  65.  
  66.  
  67. <%
  68.  
  69. MyStatement = "Insert into Book_files Set Values
  70. Title='"&Title&"',Author='"&Author&"', ISBN='"&ISBN&"',Publisher='"&Publisher&"',Place_of_Publication='"& PlaceofPublication&"',Year='"&Year&"',Collation='"&Collation &"',Shelf_Number='"&ShelfNumber&"'"
  71. Set Con = Server.CreateObject("SQLOLEDB")
  72. Con.Open "PROVIDER=SQLOLEDB;DATA SOURCE=master;UID=<hidden>;PWD=<hidden>;DATABASE=Book_files"
  73.  
  74. Con.Execute MyStatement
  75.  
  76. End IF
  77. End IF
  78.  
  79.  
  80.  
  81.  
  82.  
  83. %>
  84.  
  85. <Html>
  86. <Head><Title>Insert Data</Title></Head>
  87. <Body>
  88.  
  89. <Form Method="POST" action="/registry.html"><Head> <Center> <Font Color="Brown" Size=11 Face="Comic Sans Ms">
  90. Confirmation Page </Font> </Center>
  91.  
  92. <Body BGColor="Yellow">
  93. <Br><Br>
  94.  
  95. <%
  96.  
  97.  
  98. Response.Write(" Your Value Has Been Successfully Inserted In The Table!")
  99.  
  100.  
  101.  
  102.  
  103. End IF
  104.  
  105.  
  106. %>
  107.  
  108.  
  109. </Body>
  110.  
  111. </Html>


Edited Code - Removed username and password for database from his code (also wrapped it in code tags) - iam_clint

Reply
jhardman's Avatar
jhardman
Moderator
2,171 Posts
March 13th, 2007
06:27 PM
#11

Re: Problem inserting data to database
Alright, bseakgano. I will help you, but you must trust me and do what I say. Understand?

First off, there are several mistakes in your form. you can't name a tag attribute like this:
Code: ( text )
  1. <Input Type="Text" ISBN/ISSN="ISBN/ISSN">

and then get the data like this:
Code: ( text )
  1. ISBN = Trim(Request.Form("ISBN"))

instead it should read:
Code: ( text )
  1. <Input Type="Text" name="ISBN">

in other words, each input tag should have a name attribute which tells the name of the input, then you access that input according to the name attribute:
Code: ( text )
  1. ISBN = Trim(Request.Form("ISBN"))

You were very sloppy not using the same name you had chosen when you tried to access the input data. First, fix all of the form input names.

Second, make sure you are getting all of the input data you expect by listing them severally right before you need to use them:
Code: ( text )
  1. response.write "Author: " & request.form("author") & "<br>" & vbNewLine
  2. 'etc
This verifies that the data was passed to the script that will handle it in the way you expect it.

Third, your insert code is all within a complex if...then statement wherein if a single input is blank or mis-named the entire thing will not execute and the entered data will be lost. Unless you fix everything else, the database will never be updated. Besides that, it is very difficult for us as anonymous people on a forum to fix data base access on someone else's server. In order for your code to work on our servers, we would need a database set up identically to yours, so it is going to be difficult for us to even check.

Fourth, please fix your HTML code. Running your page through an HTML validator (see the sticky at the top of the HTML forum) would have caught several of these errors. Formatting your pages with css or even placing your inputs within a table would have aligned them better and made reading through the code easier. It is very difficult to read through someone's code where half of the code is
Code: ( text )
  1. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  2. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  3. &nbsp;&nbsp;&nbsp;&nbsp;


I have connected to different types of databases and updated databases in different ways and using different methods. If you fix those problems and post your corrected code I will help you in the next step. Oh, and post your code within code tags (the word "code" in square brackets to start, and "/code" in square brackets to finish).

Jared

Reply
bseakgano's Avatar
bseakgano
Newbie
12 Posts
March 14th, 2007
08:04 AM
#12

Re: Problem inserting data to database
I still have a problem . Now I do understand that what I am doing is not easy like I thought . Please you may do something like what I did . All I want is light . I will follow . Please believe me I have tried everything from you guys I still have the code. The worst part now is when I try to execute it turn itself into a search engine. Guys please I need you help. This my code after I try to fix something in it. But it become worse . My wish to help others with same problem in the future .
Code: ( text )
  1. <html>
  2.  
  3.      <Head> <U> <Center><Font Color="Red" Face="Garamond" Size=11> Registration Book</Font> </Center> </U>
  4.           <Title>  Registration Page </Title>
  5.       </Head>
  6.       <Body Bgcolor="Pink">
  7.              <code> <Form Method="Post" Action="lala.asp?"> </code>
  8.                          <Br>  <Br>
  9.           <B>Title                             :</B> &nbsp;&nbsp;<Input Type="Text" Name="Title">
  10.                          <Br>   <Br>
  11.           <B>Author                             :</B>&nbsp;&nbsp;&nbsp;<Input Type="Text" Author="Author">
  12.                          <Br>   <Br>
  13.            <B>ISBN     :</B>&nbsp;&nbsp;&nbsp;<Input Type="Text" ISBN/ISSN="ISBN">
  14.                          <Br>   <Br>
  15.             <B>Publisher:</B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp<Input Type="Text" Name="Publisher"><Br>   <Br>
  16.           <B>Place Of Publication:</B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<Input Type="Text" Place Of Publication="Place Of Publication"><Br>   <Br>
  17.           <B>Year:                                                                                                    </B>&nbsp;&nbsp;&nbsp;&nbsp;<Input Type="Text" Year="Year">
  18.  
  19. <br></br>
  20. <B>Collation              :</B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<Input Type="Text" Collation="Collation">
  21.  
  22. <Br>   <Br>
  23.            <B>Shelf Number         :</B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<Input Type="Text" Shelf Number="Shelf Number">
  24.                          <Br>   <Br>
  25.  
  26.                          <Br>   <Br>
  27. <Center><Input Type="Submit" Style="Font-Family:Monotype Corsiva;Color:Yellow;Font-Size:22;Font-Weight:Bold;Background:Brown" Value="Submit"></Center>
  28.              </Form>
  29.          </Body>
  30.   </Html>

ASP CODE
Code: ( text )
  1. <%
  2. category = Trim(Request.Form("registry"))
  3. If category="Book_files" then
  4. Title = Trim(Request.Form("Title"))
  5. Author = Trim(Request.Form("Author"))
  6. ISBN = Trim(Request.Form("ISBN"))
  7. Publisher = Trim(Request.Form("Publisher"))
  8. Place_of_Publication = Trim(Request.Form("PlaceofPublication"))
  9. Year = Trim(Request.Form("Year"))
  10. Collation = Trim(Request.Form("Collation"))
  11. Shelf Number = Trim(Request.Form("ShelfNumber"))
  12. If CBookTitle<>"" AND CAuthor<>"" AND IISBN<>"" AND  CPublisher<>""AND CPlaceofPublication<>"" AND IYear<>"" AND CCollation<>"" AND IShelfNu<>"" Then
  13. MySQL = "Insert into Book_files(CBook_Titles,CAuthor,IISBN,CPublisher,C  Place_of_Publication,
  14. IYear,CCollation,IShelfNu
  15. Values('"&BookTitle&"','"&Author&"','"&ISBN&"','"Publisher&"','"&PlaceofPublication&"',
  16. '"&Year&"','"&Collation&"','"&ShelfNu&"')"
  17. Set con = Server.CreateObject("ADODB.Connection")
  18. Con.Open  "Provider=SQLOLEDB;Data Source=G144379\G144379;UID=sa;Pwd=sa;DataBase=Brun  o;
  19.  
  20. response.write "Title: " & request.form("Title") & "<br>" & vbNewLine
  21. ',"Author: " & request.form("author") & "<br>" & vbNewLine
  22. ',"ISBN: " & request.form("ISBN") & "<br>" & vbNewLine
  23. ',"Publisher: " & request.form("Publisher") & "<br>" & vbNewLine
  24. ',"Place of Publication: " & request.form("Place of Publication") & "<br>" & vbNewLine
  25. ',"Year: " & request.form("Year") & "<br>" & vbNewLine
  26. ',"Collation: " & request.form("Collation") & "<br>" & vbNewLine
  27. ',"Shelf Number: " & request.form("Shelf Number") & "<br>" & vbNewLine
  28.  
  29. Con.Execute MySQL
  30. end if
  31.  
  32.  
  33.  
  34. %>
  35. <Html>
  36.    <Head> <Center> <Font Color="Brown" Size=11 Face="Comic Sans Ms">
  37. Confirmation Page </Font> </Center>
  38.         <Title> Results Returned By Active Server Pages </Title>
  39.    </Head>
  40.    <Body BGColor="Yellow">
  41.        <Br><Br>
  42.  
  43.  
  44. <%
  45.  
  46. Response.Write ("Your Value Has Been Successfully Inserted In The Table!")
  47.    End If
  48.  
  49.  
  50. %>
  51.  
  52.  
  53.    </Body>
  54. </Html>





SQL is Like This
Code: ( text )
  1. Create  table Book_file
  2. (
  3. Title char(100)not null,
  4. Author char(100)not null,
  5. ISBN into,
  6. Publisher char(100),
  7. Place_of_Publisher char(100),
  8. Year into,
  9. Collation varchar(100),
  10. Shelf_number int
  11. )

Last edited by jhardman : March 27th, 2008 at 02:09 AM. Reason: put code in code tags. Please note button marked - #
Reply
jhardman's Avatar
jhardman
Moderator
2,171 Posts
March 14th, 2007
07:54 PM
#13

Re: Problem inserting data to database
try this exact code. Don't change a thing:
Code: ( text )
  1. <%
  2. if request.form("title") = "" then %>
  3.     <html>
  4.         <Head>
  5.             <Title>Registration Page</Title>
  6.             <style>
  7.                 <!--
  8.  
  9.                 label {
  10.                     color: black;
  11.                     position: relative;
  12.                     left: 40px;
  13.                 }
  14.  
  15.                 input {
  16.                     position: absolute;
  17.                     top: inherit;
  18.                     left: 220px;
  19.                 }
  20.  
  21.                 fieldset {
  22.                     border: 0px;
  23.                     padding: 5px;
  24.                 }
  25.  
  26.                 -->
  27.             </style>
  28.         </head>
  29.         <body style="background-color: pink">
  30.             <h1 style="text-align: center; text-decoration: underline;font:Garamond
  31.             san-serif 16pt;color:'Red'"> Registration Book</h1>
  32.             <Form Method="Post" Action="lala.asp">
  33.                 <fieldset><label for="title">Title:</label><input type="text"
  34.                 name="title" value="<%=request.form("title")%>"></fieldset>
  35.                 <fieldset><label for="author">Author:</label><Input type="text"
  36.                 name="author" value="<%=request.form("author")%>"></fieldset>
  37.                 <fieldset><label for="isbn">ISBN/ISSN:</label><Input type="text"
  38.                  name="isbn" value="<%=request.form("isbn")%>"></fieldset>
  39.                 <fieldset><label for="publisher">Publisher:</label><Input type="text"
  40.                  name="publisher" value="<%=request.form("publisher")%>"></fieldset>
  41.                 <fieldset><label for="place">Place of Publication:</label><Input
  42.                  type="text" name="place" value="<%=request.form("place")%>"></fieldset>
  43.                 <fieldset><label for="year">Year:</label><Input type="text"
  44.                 name="year" value="<%=request.form("year")%>"></fieldset>
  45.                 <fieldset><label for="collation">Collation:</label><Input
  46.                  type="text" value="<%=request.form("collation")%>" name="collation"></fieldset>
  47.                 <fieldset><label for="shelf">Shelf Number:</label><Input
  48.                  type="text" name="shelf" value="<%=request.form("shelf")%>"></fieldset>
  49.                 <fieldset style="text-align: center"><Input type="submit"
  50.                  style="Font-Family:Monotype Corsiva;
  51.                     Color:Yellow;Font-Size:22;Font-Weight:Bold;Background:Brown"
  52.                  Value="Submit"></fieldset>
  53.                
  54.             </Form>
  55.         </Body>
  56.     </Html>
  57.  
  58. <%
  59. else
  60.     'category = Trim(Request.Form("registry"))
  61.     'If category="Book_files" then
  62.         dim fld, inp, objCon, objRS
  63.         for each inp in request.form
  64.             response.write inp & ": " & request.form(inp) & "<br>" & vbNewLine
  65.         next
  66.  
  67.         'Title = Trim(Request.Form("Title"))
  68.         'Author = Trim(Request.Form("Author"))
  69.         'ISBN = Trim(Request.Form("ISBN"))
  70.         'Publisher = Trim(Request.Form("Publisher"))
  71.         'Place_of_Publication = Trim(Request.Form("PlaceofPublication"))
  72.         'Year = Trim(Request.Form("Year"))
  73.         'Collation = Trim(Request.Form("Collation"))
  74.         'Shelf Number = Trim(Request.Form("ShelfNumber"))
  75.         'If CBookTitle<>"" AND CAuthor<>"" AND IISBN<>"" AND CPublisher<>""AND CPlaceofPublication<>"" AND IYear<>"" AND CCollation<>"" AND IShelfNu<>"" Then
  76.         'MySQL = "Insert into Book_files(CBook_Titles,CAuthor,IISBN,CPublisher,C   Place_of_Publication,IYear,CCollation,IShelfNu
  77.         'Values('"&BookTitle&"','"&Author&"','"&ISBN&"','"Publisher&"','"& PlaceofPublication&"','"&Year&"','"&Collation&"','"&ShelfNu&"')"
  78.         Set objCon = Server.CreateObject("ADODB.Connection")
  79.         objCon.Open "Provider=SQLOLEDB;Data Source=G144379\G144379;UID=sa;Pwd=sa;DataBase=Brun   o;
  80.         set objRS = Server.CreateObject("ADODB.Recordset")
  81.         objRS.open "SELECT * FROM [Book_files]", objCon
  82.  
  83.         for each fld in objRS.fields
  84.             response.write fld.name & "<br>" & vbNewLine
  85.         next
  86.  
  87.         'response.write "Title: " & request.form("Title") & "<br>" & vbNewLine
  88.         ',"Author: " & request.form("author") & "<br>" & vbNewLine
  89.         ',"ISBN: " & request.form("ISBN") & "<br>" & vbNewLine
  90.         ',"Publisher: " & request.form("Publisher") & "<br>" & vbNewLine
  91.         ',"Place of Publication: " & request.form("Place of Publication") & "<br>" & vbNewLine
  92.         ',"Year: " & request.form("Year") & "<br>" & vbNewLine
  93.         ',"Collation: " & request.form("Collation") & "<br>" & vbNewLine
  94.         ',"Shelf Number: " & request.form("Shelf Number") & "<br>" & vbNewLine
  95.  
  96.         'Con.Execute MySQL
  97.     'end if %>
  98.  
  99.     <Html>
  100.     <Head> <Center> <Font Color="Brown" Size=11 Face="Comic Sans Ms">
  101.     Confirmation Page </Font> </Center>
  102.     <Title> Results Returned By Active Server Pages </Title>
  103.     </Head>
  104.     <Body BGColor="Yellow">
  105.     <Br><Br>
  106.     <%
  107.  
  108.     'Response.Write ("Your Value Has Been Successfully Inserted In The Table!")
  109. End If %>
  110.  
  111. </Body>
  112. </Html>
  113.  
  114. <!--
  115.  
  116. SQL is Like This
  117.  
  118. Create table Book_file
  119. (
  120. Title char(100)not null,
  121. Author char(100)not null,
  122. ISBN into,
  123. Publisher char(100),
  124. Place_of_Publisher char(100),
  125. Year into,
  126. Collation varchar(100),
  127. Shelf_number int
  128. )
  129. -->


Save the entire thing as one file named lala.asp. Run it and let me know what happened

Reply
bseakgano's Avatar
bseakgano
Newbie
12 Posts
March 15th, 2007
09:27 AM
#14

Re: Problem inserting data to database
Now I see things i don't understand. Or is it because i might be kicked out. I don't know. Though i last did coding by the year 2002. I was unemployed until few weeks back. To do some project but now is hard to code it down.

Though back to the ASP now. When i copy and paste the whole code. It fail to open but when i take Html alone ,it desplays A mixer . I mean at Title i get something like this ">Title and at Author is like this Au">thor. But this on top of u.It shows a mixed up of codes and signs. Some and when i