ASP Veri Tabanı Erişim Uygulamaları Örnek 5

ASP Veri Tabanı Erişim Uygulamaları Örnek 5

ASP Veri Tabanı Erişim Uygulamaları Örnek 5

Bu örneğimizde, emlak ajansındaki evlerin özelliklerine göre kayıt ekleme operasyonu ele alınmaktadır. Menu.asp dosyası insert.asp dosyasına parametre göndermektedir.

Menu.asp

22. Veri tabanı bağlantısı için değişken tanımı.

23. Veri taanı bağlantısı kullanılarak access dosyasının açılması.

29. Post metodu kullanılarak, insert.asp dosyasına bu form içerisindeki parametreler yollanır.

36. SQL deyimi oluşturulur.

37. SQl deyimi çalıştırılır.

42. Kayıt kümesi sonuna erişilene kadar döngü oluşturur.

43. Category değişkenine kayıt kümesindeki category değeri atanır e liste kutusu doldurulana kadar kayıt kümesindeki bir sonraki satıra 45. satırda geçilir.

46. Döngü başa döndürülür.

53. satırda da bir sql deyimi oluşturulmaktadır.

54. satırda ise kayıt kümesini elde etmek için sql deyimi çalıştırılmaktadır.

Insert.asp

24. satırda kayıt kümesi metodu ile bir değişken tanımlanıyor.

25. DSN=Real deyimi ODBC üzerinden veri tabanına bağlanılıyor.

26. category değişkenine, menu1 değişkenin tanımlanıldığı formdan gönderilen değer atanıyor.

87. satırda session nesnesi kullanılarak, oturum numarasına göre işlem yapılmaktadır.

88. satırda bir insert deyimi oluşturulmaktadır.

Menu.asp

  1. <html>
  2. <head>
  3. <meta http-equiv=”Content-Type” content=”text/html; charset=windows-1254”>
  4. <title>new advertisement form</title>
  5. <meta name=”GENERATOR” contet=”Microsoft FrontPage 3.0”>
  6. </head>
  7. <body bgcolor=”#FFFF80”>
  8. <div align=”center”><center>
  9. <table border=”1” width=”597” height=”1”>
  10. <tr>
  11. <td width=”166” height=”1” background=”Duvar.jpg”><p align=”center” ><img src=”STUGA.gif”
  12. width=”140” height=”89” alt=”STUGA.gif(6111 bytes)”></td>
  13. <td width=”223” height=”1” valign=”bottom”><p align=”center”><font
  14. face=”Copperplate Gothic Bold” color=”#800000” size=”4”><strong>NetSPage<7strong></font></p>
  15. <p align=”center”><font face=”Lucida Handwriting” color=”#800000” size=”4”>REAL ESTATE</font></td>
  16. <td width=”190” height=”1” background=”Duvar.jpg”><p align=”center”><img src=”STUGA.gif”
  17. width=”140” height=”89” alt=”STU gif (6111 bytes)”></td>
  18. </tr>
  19. </table>
  20. </center></div>
  21. <%
  22. set conntemp=server.createobject(”adodb.connection”)
  23. conntemp.open ”DRIVER={Microsoft Access Driver(*.mdb)}; DBQ=c:\Inetpub\wwwroot\program\netspage.dmb”
  24. %>
  25. <p align=”center”><big><font color=”#000080” face=”Arial”><strong>NEW ADVERTISEMENT FORM</strong></font></big></p>
  26. <hr size=”4” color=”#800000”>
  27. <p align=”center”><small><font face=”Arial”><small><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  28. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong></small></font></small></p>
  29. <form method=”POST” action=”insert.asp”>
  30. <table border=”1” width=”103%” bordercolor=”#FFFF80” bordercolorlight=”#FFFF80”
  31. nordercolordark=”#FFFF80” eight=”570”
  32. style=”font-family: Book Antiqua; font-size: 12pt; color: rgb(0,0,128)”>
  33. <tr>
  34. td width=”25%” height=”24”><div align=”left”><p>Category :</td>
  35. td width=”25%” height=”24”>
  36. <%sqltemp=”slect distinct Category from RealEstate”
  37. set rstemp=conntemp.execute(sqltemp)
  38. %>
  39. <p>select name=”menu1” size=”1”
  40. style=”font-size:10pt; font-family: Book Antiqua; color: rgb(0,0,128); margin:auto”>
  41. <option selected value=”other”>other</option
  42. <% do while not rstemp.eof
  43. category=rstemp(”Category”)%>
  44. <option value=”<%=category%>”><%=category%></option>
  45. <% rstemp.movenext
  46. loop %> </select></td>
  47. <td width=”22%” height=”24”>If nother specify :<input type=”text” name=”T13” size=”20”
  48. style=”font-family: Book Antqua; font-size: 10pt”></td>
  49. </tr>
  50. <tr>
  51. <td width =”25%” height=”24”>Location :</td>
  52. <td width=”25%” height=”24”>
  53. <%sqltemp=”select distinct Location from RealEstate”
  54. set rstemp=conntempt.execute(sqltemp) %>
  55. <p><select name=”menu” size=”1”
  56. style=”font-size: 10pt; font-family: Book Antiqua; color: rgb(0,0,128)”>
  57. <option selected value=”other”>other</option>
  58. <% do while not rstemp.eof
  59. category=rstemp(”Location”)%>
  60. <option value=”<%=category%>”><%=category%></option>
  61. <% rstemp.movenext
  62. loop %>
  63. </select></td>
  64. <td width=”22%” height=”24”>If other specify:<input type=”text” name=”T14” size=”20”
  65. style=”font-family: Book Antiqua; font-size: 10pt; color: rgb(0,0,128)”></td>
  66. </tr>
  67. <tr>
  68. <td width=”25%” height=”24”>Status :</td>
  69. <td width=”25%” height=”24”><%sqltemp=”select distinct Status from RealEstate”
  70. set rstemp=conntempt.execute(sqltemp) %>
  71. <p><select name=”D1” size=”1”
  72. style=”font-family: Book Antiqua; font-size: 10pt; color; rgb(0,0,128)”>
  73. <% do while not rstemp.eof
  74. categ0ry=rstemp(”Status”)%>   <option value=”<%=category%>”><%=category%></option>
  75. <% rstemp.movenext
  76. loop %>  </select></td>
  77. <td width=”22%” height=”24”></td>
  78. </tr>
  79. <tr>
  80. <td width=”25%” height=”38”>DETAILS</td>
  81. <td width=”25%” height=”38”></td>
  82. <td width=”22%” height=”38></td>
  83. </tr>
  84. <tr>
  85. <td width=”25%” height=”24”>Conditions:</td>
  86. <td width=”25%” eight=”24”><%sqltemp=”select distinct Conditions from RealEstate”
  87. set rstemp=conntemp.execute(sqltemp) %>
  88. <p><select name=”menu9” size=”1”
  89. style=”font-size: 10pt; font-family: Book Antiqua; color: rgb(0,0,128)”>
  90. <% do while not rstemp.eof
  91. category=rstemp(”Conditions”)%> <option value=”<%=category%>”><%=category%></option>
  92. <% rstemp.movenext
  93. loop %>   </select></td>
  94. <td width=”22%” height=”24”></td>
  95. </tr>
  96. <tr>
  97. <td width=”25%” height=”38”>Number Of Stor<big>e</big>y</td>
  98. <td width=”25%” height=”38”><input type=”text” name=”T5” size=”20”
  99. style=”font-family: Book Antiqua; font-size: 10pt; color: rgb(0,0,128)”></td>
  100. <td width=”22%” height=”38”></td>
  101. </tr>
  102. <tr>
  103. <td width=”25%” height=”38”>Number of Bathrooms</td>
  104. <td width=”25%” height=”38”><iput type=”text” name=”T6” size=”20”
  105. style=”font-family: Book Antiqua; font-size: 10pt; color: rgb(0,0,128)”></td>
  106. <td width=”22%” height=”38”></td>
  107. </tr>
  108. <tr>
  109. <td width=”25%”  height=”38”>Number Of Rooms</td>
  110. <td width=”25%” height=”38”><input type=”text” name=”T7” size=”20”
  111. style=”font-family: Book Antiqua; font-size: 10pt; color: rgb(0,0,128)”></td>
  112. <td width=”22%” height=”38”></td>
  113. </tr>
  114. <tr>
  115. <td width=”25%” height=”38”>Number of Balconies</td>
  116. <td width=”25%” height=”38”><input type=”text” name=”T8” size=”20”
  117. style=”font-family: Book Antiqua; font-size: 10pt; color: rgb(0,0,128)”></td>
  118. <td width=”22%” height=”38”></td>
  119. </tr>
  120. <tr>
  121. <td width=”25%” height=”38”>Heating System</td>
  122. <td width=”25%” height=”38”><%sqltemp=”select distinct Heating from RealEstate”
  123. set rstemp=conntempt.execute(sqltemp)%>
  124. <p>select name=”menu10” size=”1”
  125. style=”font-size: 10pt; font-family: Book Antiqua; color: rgb(0,0,128)”>
  126. <option selected value=”other”>other</option>
  127. <%do while not rstemp.eof
  128. category=rstemp(”Heating”)%> <option value=”<%=category%>”><%=category%></option>
  129. <% rstemp.movenext
  130. loop %> </select></td>
  131. <td width=”22%” height=”38”>If other specify:<input type=”text” name=”T17” size=”20”
  132. style=”font-family: Book Antiqua; font-size: 10pt; color: rgb(0,0,128)”></td>
  133. </tr>
  134. <tr>
  135. <td width=”25%” height=”13”>Garden</td>
  136. <td width=”25%” height=”13”><input type=”checkboz” name=”C1” value=”ON”></td>
  137. <td width=”22%” height=”13”></td>
  138. </tr>
  139. <tr>
  140. <td width=”25%” height=”19”>Garage</td>
  141. <td width=”25%” height=”19”><input type=”checkboz” name=”C2” value=”ON”></td>
  142. <td width=”22%” height=”19”></td>
  143. </tr>
  144. <tr>
  145. <td width=”25%” height=”24”>urnished</td>
  146. <td width=”25% height=”24”><input type=”checkbox” name=”C3” value=”ON”></td>
  147. <td width=”22%” height=”24”></td>
  148. </tr>
  149. <tr>
  150. <td width=”25%” height=”24”>Size (in m2)</td>
  151. <td width=”25%” height=”24”><input type=”text” name=”T11” size=”20”
  152. style=”font-family: Book Antiqua; font-size: 10pt; color: rgb(0,0,128)”></td>
  153. <td width=”22%” height=”24”></td>
  154. </tr>
  155. <tr>
  156. <td width=”25%” height=”24”>Price (millions)</td>
  157. td width=”25%” height=”24”><input type=”text” name=”T12” size=”20”
  158. style=”font-family: Book Antiqua; font-size: 10pt; color: rgb(0,0,128)”></td>
  159. <td width=”2%” height=”24”><td
  160. </tr>
  161. <tr>
  162. <td width=”25%” height=”19”>LOCATION</td>
  163. <td width=”25%” height=”19”></tdd>
  164. <td width=”22%” height=”19”></td>
  165. </tr>
  166. <tr>
  167. <td width=”25%” height=”25”>Province</td>
  168. <td width=”25%” height=”25”><input type=”text” name=”T9” size=”20”
  169. style=”font-family: Book Antiqua; font-size: 10pt”></td>
  170. <td width=”22%” height=”25”></td>
  171. </tr>
  172. <tr>
  173. <td width=”25%” height=”25”>City</td>
  174. <td width=”25%” height=”25”>input type=”text” name=”T10” size=”20”
  175. style=”font-family: Book Antiqua; font-size: 10pt; color: rgb(0,0,128)”></td>
  176. <td width=”22%” height=”25”></td>
  177. </tr>
  178. <tr>
  179. <td width=”25%” height=”19”>Extra</td>
  180. <td width=”25%” height=”19”><textarea rows=”3” name=”S1” cols=”20”
  181. style=”font-family: Book Antiqua; font-size: 10pt; color: rgb(0,0,128)”></textarea></td>
  182. <td width=”22%” height=”19” valign=”top”><input type=”submit” value=”Submit Form”
  183. name=”B1”
  184. style=”font-family: Book Antiqua; font-size: 10pot; backgroundcolor: rgb(0,0,128); color: rgb(255, 255, 255)”><p><inpu
  185. type=”reset” value=”Reset form” name=”b2”
  186. style=”font-family: Book Antiqua; font-size: 10pt; backgroundcolor: rgb(0,0,128); color: rgb (255, 255, 255)”></td>
  187. </tr>
  188. </table>
  189. </form>
  190. <p align=”center”>&nbsp;</p>
  191. <p align=”center”><small><font face=”Arial”><small><strong>&nbsp;</strong></small></font></small>
  192. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  193. </p>
  194. <hr size=”4” color=”#8000000” align=”center”>
  195. <p align=”center”><small><small><strong>MibitoNet Company, Istanbul&nbsp; </strong><a
  196. href=”mailto:mibito@softhome.net”><img src=”HH01580A.gif” width=”44” height=”36”
  197. alt=”HH01580A.gif (1311 bytes)”></a></small></small></p>
  198. <p align=”center”>&nbsp;</p>
  199. <p align=”center”>&nbsp;</p>
  200. <p align=”center”>&nbsp;</p>
  201. <p align=”center”>&nbsp;</p>
  202. <p align=”center”>&nbsp;</p>
  203. <p align=”center”>&nbsp;</p>
  204. <p align=”center”>&nbsp;</p>
  205. <p align=”center”>&nbsp;</p>
  206. <p align=”center”>&nbsp;</p>
  207. <p align=”center”>&nbsp;</p>
  208. <% rstemp.close
  209. set rstemp=nothing
  210. conntemp.close
  211. set conntempt=Nothing
  212. %>
  213. </body>
  214. </html>

insert.asp

  1. <html>
  2. <head>
  3. <meta http-equiv=”Content-Type” content=”text/html; charset=windows-1254”>
  4. <title>Insertion</title>
  5. </head>
  6. <body bgcolor=”#F
  7. <div align=”center”><center>
  8. <table border=”1” width=”597” height=”1”>
  9. <tr>
  10. <td width=”166” height=”1” background=”Duvar.jpg”><p align=”center”><img src=”STUGA.gif”
  11. width=143” height=”91” alt=”STUGA.gif (6111 bytes)”></td>
  12. <td width=”223” height=”1” valign=”bottom”><p align=”center”><font
  13. face=”Copperplate Gothic Bold” color=”#800000” size=”4”><strong>Net SPage</strong></font></p>
  14. <p align=”center”><font face=”Lucida Handwriting” color=”#800000” size=”4”>REAL ESTATE</font></td>
  15. <td width=”190” height=”1” background=”Duvar.jpg”><p align=”center”><img src=”STUGA.gif”
  16. width=”143” height=”91” alt=”STUGA.gif(6111 bytes)”></td>
  17. </tr>
  18. </table>
  19. </center></div>
  20. <p align0”center”><font  face=”Arial”
  21. <hr size=”5” color=”#800000”>
  22. <!–#INCLUDE VIRTUAL=”program/reelestate/adovbsçinc” –>
  23. <%
  24. set rstemp=Server.CreateObject(”ADODB.Recordset”)
  25. connectme= ”DSN=Real”
  26. category=request.form(”menu1”)
  27. if category0”other” then
  28. category=requet.form(”T13”)
  29. end if
  30. location=request.form(”menu2”)
  31. if location=”other” then
  32. location=request.form(”T14”)
  33. end if
  34. Status=request.form(”D1”)
  35. room=request.form(”T7”)
  36. if room=””then
  37. introom=0
  38. else
  39. introom=int(room)
  40. end if
  41. bathroom=request.form(”T6”)
  42. if bahtroom=”” then
  43. intbaath=0
  44. else
  45. intbath0int (bathroom)
  46. end if
  47. story=request.form(”T5”)
  48. if story=”” then
  49. intstory=0
  50. else
  51. intstory=int(story)
  52. end if
  53. balcony=request.form(”T8”)
  54. if balcony=” ”then
  55. intbalcony=0
  56. else
  57. intbalcony=int(balcony)
  58. end if
  59. size=request.form(”T11”)
  60. if size=””then
  61. intsize=0
  62. else
  63. intsize=int
  64. end if
  65. price=request.form(”T12”)
  66. if price=” ”then
  67. intprice=0
  68. else
  69. intprice=int(price)
  70. end if
  71. conditions=request.form(”menu9”)
  72. garden=request.form(”C1”)
  73. garage=request.form(”C2”)
  74. furnished=request.frm(”C3”)
  75. heat=request.form(”menu10”)
  76. if heat=”other” then
  77. heat=request.form(”T17”)
  78. end if
  79. province=request.form(”T9”)
  80. city=request.form(”T10”)
  81. extra=request.form(”S1”)
  82. if ((category=””) or (location=””) or (heat=””) or (province=””) or (city=””)) then%>
  83. <p><font face=”Book Antiqua” color=”#000080”><big>You should fill the form completely <a
  84. href=”newadvert.asp”>Back</a></big></font></p>
  85. <%reponse.end
  86. else
  87. id=sessions(”id”)
  88. sqltemp = ”insert into RealEstate (ID, Category, Location, Province, City, Conditions, Status, Furnished, No_of_rooms,
  89. No_of_bathrooms, No_of_balconies, Heating, Storu, Size, Garage, Garden, Price, Extra)”
  90. sqltemp=sqltemp & ”values(”’ &id & ” ‘ ”
  91. sqltemp=sqltemp& ”, ‘ ” &category&” ‘ ”
  92. sqltemp=sqltemp& ”, ‘ ” &location& ” ‘ ”
  93. sqltemp=sqltemp& ”, ‘ ”&province&” ‘ ”
  94. sqltemp=sqltemp&”, ‘ ” &city& ” ‘ ”
  95. sqltemp=sqltemp& ”, ‘ ”&conditions&” ‘ ”
  96. sqltemp=sqltemp&”, ‘ ” &Status& ” ‘ ”
  97. if furnished=”ON” then
  98. sqltemp=sqltemp&”, ‘yes’ ”
  99. else
  100. sqltemp=sqltemp& ”, ‘no’ ”
  101. end if
  102. sqltemp=sqltemp& ”, ”&introom
  103. sqltemp=sqltemp& ”, ”&intbath
  104. sqltemp=sqltemp& ”, ” &intbalcony
  105. sqltemp=sqltemp& ”, ‘ ” & heat & ” ‘ ”
  106. sqltemp=sqltemp& ”, ” &intstory
  107. sqltemp=sqltemp& ”, ”&intsize
  108. if garage=”ON”then
  109. sqltemp=sqltemp& ”, ‘yes’ ”
  110. else
  111. sqltemp=sqltemp& ”, ‘no’ ”
  112. end if
  113. if garden=”ON” then
  114. sqltemp=”sqltemp& ”, ‘yes” ”
  115. else
  116. sqltemp=sqltemp& ”, ‘no ‘ ”
  117. end if
  118. sqltemp=sqltemp& ”, ” &intprice
  119. sqltemp=sqltemp& ”, ‘ ” &extra& ” ‘)”
  120. rstemp.open sqltemp, connectme
  121. %>
  122. <p><font face=”Book Antiqua” color=”#000080”>Your advertisement is stored successfully</font></p>
  123. <%session.abandon
  124. end if
  125. %>
  126. <p>&nbsp;</p>
  127. <p align=”center”>< href=”realindex.htm”>REAL ESTATE HOME</a></p>
  128. <hr size=”5” color=”#800000”>
  129. <p align=”center”><small><small><strong><a href=”mailto:mibito@softhome.net”>MibitoNet
  130. Company, Istanbul</a>&nbsp;</strong></small></small>&nbsp; <a
  131. href=”mailto:mibitoqsofthome.net”><img src=”HH01580A.gif” alt=”HH01580A.gif (1311 bytes)”
  132. width=”50” height=”44”></a>&nbsp;&nbsp; </p>
  133. </body>
  134. </html>

Bu gönderiyi paylaş

Bir cevap yazın