Jump to content

DATABASE Won't update


chrepair
 Share

Recommended Posts

I made an update page from the examples on this site(ASP UPDATE) and changed the code to match the field names in my database. I have a ASP page that displays all data in my data base and that works perfectly. This new update page I made from the ASP UPDATE EXAMPLE displays the DB data and in the first field there is a button to press so u can change that line's data. That works and when u press the button the next page appears with all teh fields in that row. I change the data in one of the fields, hit update and then the page changes and says congradulations "field name" was successfully updated, but, in reality the database reflects NO changes. Any idea's why this is happening? I get no errors but nothing changes in te database.PLEASE HELP AS THIS IS DRIVING ME CRAZY!Here is the code on the UPDATE.asp page:<html><body><%set conn=Server.CreateObject("ADODB.Connection")conn.Provider="Microsoft.Jet.OLEDB.4.0"conn.Open "northwind.mdb"set rs=Server.CreateObject("ADODB.Recordset")rs.open "SELECT * FROM greg",conn%><table border="1" width="75%"><tr><%for each x in rs.Fields response.write("<th>" & ucase(x.name) & "</th>")next%></tr><% do until rs.EOF %><tr><form method="post" action="demo_update.asp"><%for each x in rs.Fields if lcase(x.name)="time" then%> <td> <div align="left"> <input type="submit" name="time" value="<%=x.value%>"> </div></td> <%else%> <td><%Response.Write(x.value)%> <div align="center"></div></td> <%end ifnext%></form><%rs.MoveNext%></tr><%loopconn.close%></table><FORM> <div align="center"> <INPUT TYPE="button" VALUE="Back" onClick="history.go(-2);return true;"> </div> </FORM></body></html>HERE IS THE CODE ON THE UPDATE_DEMO.ASP page:<html><body><h2>Update Record</h2><%set conn=Server.CreateObject("ADODB.Connection")conn.Provider="Microsoft.Jet.OLEDB.4.0"conn.Open "northwind.mdb"cid=Request.Form("time")if Request.form("monday")="" then set rs=Server.CreateObject("ADODB.Recordset") rs.open "SELECT * FROM greg WHERE time='" & cid & "'",conn %> <form method="post" action="demo_update.asp"> <table> <%for each x in rs.Fields%> <tr> <td><%=x.name%></td> <td><input name="<%=x.name%>" value="<%=x.value%>"></td> <%next%> </tr> </table> <br /><br /> <input type="submit" value="Update record"> </form><%else sql="UPDATE greg SET " sql=sql & "Monday='" & Request.Form("Monday") & "'," sql=sql & "Tuesday='" & Request.Form("tuesday") & "'," sql=sql & "Wednesday='" & Request.Form("wednesday") & "'," sql=sql & "Thursday='" & Request.Form("thursday") & "'," sql=sql & "Friday='" & Request.Form("friday") & "'," sql=sql & "Saturday='" & Request.Form("saturday") & "'" sql=sql & " WHERE Sunday='" & time & "'" on error resume next conn.Execute sql if err<>0 then response.write("No update permissions!") else response.write("Record " & cid & " was updated!") end if end ifconn.close%></body><FORM> <INPUT TYPE="button" VALUE="Back" onClick="history.go(-2);return true;"> </div> </FORM></html>ANY IDEAS?

Link to comment
Share on other sites

Your mistake is in your SQL statement

sql="UPDATE greg SET "sql=sql & "Monday='" & Request.Form("Monday") & "',"sql=sql & "Tuesday='" & Request.Form("tuesday") & "',"sql=sql & "Wednesday='" & Request.Form("wednesday") & "',"sql=sql & "Thursday='" & Request.Form("thursday") & "',"sql=sql & "Friday='" & Request.Form("friday") & "',"sql=sql & "Saturday='" & Request.Form("saturday") & "'"sql=sql & " WHERE Sunday='" & time & "'"

change the above to

sql="UPDATE greg SET "sql=sql & "Monday='" & Request.Form("Monday") & "',"sql=sql & "Tuesday='" & Request.Form("tuesday") & "',"sql=sql & "Wednesday='" & Request.Form("wednesday") & "',"sql=sql & "Thursday='" & Request.Form("thursday") & "',"sql=sql & "Friday='" & Request.Form("friday") & "',"sql=sql & "Saturday='" & Request.Form("saturday") & "',"sql=sql & "Sunday='" & time & "'"sql=sql & " WHERE time='" & cid & "'"

or something ot that effect. You weren't setting the Sunday field you were using it as a condition...I don;t thing that is what you meant to do, is it?

Link to comment
Share on other sites

Your mistake is in your SQL statement
sql="UPDATE greg SET "sql=sql & "Monday='" & Request.Form("Monday") & "',"sql=sql & "Tuesday='" & Request.Form("tuesday") & "',"sql=sql & "Wednesday='" & Request.Form("wednesday") & "',"sql=sql & "Thursday='" & Request.Form("thursday") & "',"sql=sql & "Friday='" & Request.Form("friday") & "',"sql=sql & "Saturday='" & Request.Form("saturday") & "'"sql=sql & " WHERE Sunday='" & time & "'"

change the above to

sql="UPDATE greg SET "sql=sql & "Monday='" & Request.Form("Monday") & "',"sql=sql & "Tuesday='" & Request.Form("tuesday") & "',"sql=sql & "Wednesday='" & Request.Form("wednesday") & "',"sql=sql & "Thursday='" & Request.Form("thursday") & "',"sql=sql & "Friday='" & Request.Form("friday") & "',"sql=sql & "Saturday='" & Request.Form("saturday") & "',"sql=sql & "Sunday='" & time & "'"sql=sql & " WHERE time='" & cid & "'"

or something ot that effect. You weren't setting the Sunday field you were using it as a condition...I don;t thing that is what you meant to do, is it?

I am not all that familiar with what this is actually doing.I made the changes and now I am getting that pre-defined error in the code "No update permissions".Not sure what is up now?CORRECTION: I GOT IT!! YEAH!!!!I had to add 1 more line to it and now it works.sql=sql & "Saturday='" & Request.Form("saturday") & "'," sql=sql & "Sunday='" & Request.Form("sunday") & "'" sql=sql & " WHERE time='" & cid & "'"Question, in this code how do I make the display show up as AVAILABLE if a field is blank in the database and if there is ANYTHING written in a field the display page will show RESERVED?Here is the code (it should look familiar as we wrre working on it before):<meta http-equiv="refresh" content="30"> <html><style>#MainTable th{ width: 50px; color: #000099; font-size: 24; font-family:andy;}</style><style type="text/css"><!--.style1 { font-family: Georgia, "Times New Roman", Times, serif; font-size: 10px;}body { background-color: #000000;}--></style><%dim nameaval="AVAILABLE"%><body><%set conn=Server.CreateObject("ADODB.Connection")conn.Provider="Microsoft.Jet.OLEDB.4.0"conn.Open(Server.Mappath("northwind.mdb"))set rs = Server.CreateObject("ADODB.recordset")sql="SELECT Time, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday FROM greg"rs.Open sql, conn%><table id="MainTable" width="750" height="20" border="2" align="center" cellpadding="0" bordercolor="#0000FF" bgcolor="#00FFFF"><tr><%for each x in rs.Fields response.write("<th align='center' bgcolor='#00CCFF' font-family:andy>" & x.name & "</th>")next%></tr><%do until rs.EOF%> <tr> <%for each x in rs.Fieldsif x.name = "Time" then%><td align="center" valign="middle" style="background-color:#000099;font-family:Andy;color:#FFFF00;font-size:15pt;font-weight:bold;border:1px solid #666666"><%else%><td align="center" valign="middle" style="background-color:#66FFFF;font-family:Georgia;color:#663300;font-size:12pt;font-weight:normal;border:1px solid #666666"> <span class="style1"><%end if%><%Response.Write(x.value)%></div> </span> <div align="center"></div></td><%next rs.MoveNext%> </tr><%looprs.closeconn.close%></table></body></html>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...