By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,645 Members | 1,048 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,645 IT Pros & Developers. It's quick & easy.

Can't seem to crack updating a database

P: 21
Hi it's me again, still working on the sam 5 minute problem so feeling kind of thick now.

I've dumped the idea of using a textarea for now and am using a textbox instead but am struggling when it comes to updating the database, I've tried several different methods and the one I'm currently battling with is as follows:
Expand|Select|Wrap|Line Numbers
  1. %
  2. set objconn=server.CreateObject("ADODB.connection")
  3. objconn.Mode=3
  4. objconn.Open ("DSN=localserver; User ID=blah; Password=blah; DATABASE=blah; APP=ASP Script")
  5. set rs2=objconn.execute ("SELECT EmailType from Grades_email_tbl")
  6. %> 
  7. <%
  8. Dim strEmailType
  9. strEmailType = Request.Form("Select1")
  10. %>  
  11. <form method="post" action="email.asp">
  12.  
  13. <select name=select1>
  14.  
  15. <%do while not rs2.eof %>
  16. <option><%=rs2(0)%></option>
  17. <%
  18. rs2.movenext
  19. loop
  20. rs2.Close 
  21. set rs2 = nothing
  22. %>
  23. </select>
  24. <% 
  25. Dim query
  26. query = "SELECT emailContents FROM Grades_email_tbl WHERE EmailType ='"&strEmailType&"'"
  27. set rs3 = server.createObject("ADODB.recordset")
  28. rs3.LockType =3
  29. rs3.open query, objConn
  30.  
  31. %>
  32. <input type=Submit value=Go! />
  33. &nbsp;
  34. &nbsp; &nbsp;
  35. Email type selected: <%=strEmailType%>
  36. <br /> 
  37. </form>
  38. <form method="post" action="emails_edit.asp" >
  39. <input name="no" type="hidden" value= <%=strEmailType%>>
  40. <table>
  41.  
  42. <input id="Text3" style="width: 200px" value=<%=rs3("emailContents")%> type="text" name="Text3" />
  43.  
  44. </table>
  45.  
  46. <input type="submit" name="action" value="Save">
  47. </form>
  48. <form name= "form2" method=post>
  49.  
  50. <tr><td align="center"  colspan="8">
  51.     &nbsp;<% 
  52.   ''Dim emailtxt
  53.   ''emailtxt= ("&Request.Form("Text1")")
  54.   ''Response.write bah("&Request.Form("emailtxt")&")
  55.   ''rs3("emailContents")=Request.Form ("emailtxt.value")
  56.   ''rs3.Update 
  57.   %><input type="submit" value="Send" name="submit1" style="width: 50px">
  58. </td></tr>
  59. </table>
  60.  
  61. </body></html>
  62.  
  63.  
  64. <%
  65. set objdb=nothing
  66. objconn.Close
  67. set objconn=nothing
  68. %>
Then the emails_edit.asp looks like:

Expand|Select|Wrap|Line Numbers
  1. <%@ Language=VBScript %>
  2. <%Option Explicit%>
  3.  
  4. <html>
  5. <body>
  6. <%
  7. Dim BolFound, rs4
  8. Dim con2
  9. set con2=server.CreateObject("ADODB.connection")
  10. con2.Open ("DSN=localserver; User ID=blah; Password=blah; DATABASE=blah; APP=ASP Script")
  11. set rs4=server.CreateObject("ADODB.recordset")
  12. rs4.LockType =3 
  13. rs4.Open "Grades_email_tbl", con2, &H0001
  14.  
  15. BolFound=false
  16.  
  17. Do while not (rs4.eof or BolFound)
  18.    If(strComp(rs4("emailType"), request("strEmailType"), vbtextcompare)=0) then
  19.      BolFound= True
  20.    Else 
  21.      rs4.movenext
  22.    End if
  23. Loop
  24. rs4("emailContents")= Request.Form("text3")
  25. rs4.update
  26. rs4.Close
  27. set rs4=nothing
  28. set Con2=nothing
  29. con2.close
  30.  
  31. %>
  32.  
  33. </body>
  34. </html>
  35.  
The select box works fine and when I hit the go button it loads the value of emailContents into my textbox, but when I his the Save button under the textbox I just get errors, the current one being a 'BOF or EOF is True" error so I'm guessing I'm not passing the values accross correctly, infact I've just confirmed that by trying to response.write r4("emailContents") so now I'm totally stumped
Oct 9 '07 #1
Share this Question
Share on Google+
3 Replies


P: 21
I think I've cracked it, a piece of code that didn't work when I tried it now seems to work.

Expand|Select|Wrap|Line Numbers
  1. <%@ Language=VBScript %>
  2. <%Option Explicit%>
  3.  
  4.  
  5. <%
  6. Dim rs4, con2, strEmailType, Query2
  7. strEmailType = request.Form("emails")
  8. Query2 = "Select * from grades_email_tbl where emailtype ='"&strEmailType&"'"
  9. set con2=server.CreateObject("ADODB.connection")
  10. con2.Open ("DSN=localserver; User ID=blah; Password=blah; DATABASE=blah; APP=ASP Script")
  11. set rs4=server.CreateObject("ADODB.recordset")
  12. rs4.LockType =3 
  13. rs4.Open Query2, con2, &H0001
  14. rs4("emailContents")= Request.Form("emailtxt")
  15. rs4.update
  16. rs4.Close
  17. set rs4=nothing
  18.  
  19. con2.close
  20. set Con2=nothing
  21. Response.Write "Your e-mail has been saved"
  22. %>
  23.  
Now all I have to do is get the second page to execute then return to the first page rather than a blank page, then figure out why another bit of code isn't e-mailing
Oct 10 '07 #2

jhardman
Expert 2.5K+
P: 3,405
I'm glad you got it working. Are you saying you are still looking at how to redirect? The code for redirecting is
Expand|Select|Wrap|Line Numbers
  1. response.redirect "firstPage.asp"
The only problem with this is that this won't send any data to firstPage.asp. You can solve this (if you need data sent) by putting the data in session variables
Expand|Select|Wrap|Line Numbers
  1. for each x in request.form
  2.    session(x) = request.form(x)
  3. next
or in querystring
Expand|Select|Wrap|Line Numbers
  1. dim nextPage
  2. nextPage = "firstPage.asp?"
  3. for each x in request.form
  4.    nextPage = nextPage & x & "=" & server.urlEncode(request.form(x)) & "&"
  5. next
  6. nextPage = left(nextPage, len(nextPage)-1)
  7. response.redirect nextPage
Let me know if this helps.

Jared
Oct 11 '07 #3

P: 21
Thanks but I cheated, I put up a message on the second page confirming the e-mail message had been saved then put a button on it to direct the user back to the first page.
Oct 11 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.