Jump to content

why UPDATE doesn't work


tjodalv
 Share

Recommended Posts

Dim doing, msgdoing = Request.QueryString("do")If doing = "edit" Then	u_ime = Request.Form("ime")	u_email = Request.Form("email")	u_lozinka = Request.Form("lozinka")	u_adresa = Request.Form("adresa")	u_zip = Request.Form("zip")	u_grad = Request.Form("grad")	u_telefon = Request.Form("telefon")	u_mobitel = Request.Form("mobitel")			If u_ime = "" OR u_email = "" Then			msg = "Required fields !"				If u_telefon = "" AND u_mobitel = "" Then					msg = "Required fields"				Else						If u_lozinka = "" Then								strSQL = "UPDATE tblKorisnici SET [ime] = '" & u_ime & "', [email] = '" & u_email & "', adresa = '" & u_adresa & "', [zip] = " & u_zip & ", grad = '" & u_grad & "', telefon = '" & u_telefon & "', mob = '" & u_mobitel & "' WHERE id = " & Request.Cookies("enekretnine")("user_id") & ";"				  dbConn.Execute(strSQL)				  msg = "Succses !"							Else								strSQL = "UPDATE tblKorisnici SET [ime] = '" & u_ime & "', [email] = '" & u_email & "', lozinka = '" & u_lozinka & "', adresa = '" & u_adresa & "', [zip] = " & u_zip & ", grad = '" & u_grad & "', telefon = '" & u_telefon & "', mob = '" & u_mobitel & "' WHERE id = " & Request.Cookies("enekretnine")("user_id") & ";"				  dbConn.Execute(strSQL)				  msg = "Succes !"							End if					End if			End ifElse	Set rsGetUserData = Server.CreateObject("ADODB.Recordset")	strSQL = "SELECT * FROM tblKorisnici WHERE id = " & Request.Cookies("enekretnine")("user_id") & ";"	rsGetUserData.Open strSQL, dbConn			If rsGetUserData.EOF Then		Response.Redirect "default.asp"	Else		ime = rsGetUserData("ime")		email = rsGetUserData("email")		adresa = rsGetUserData("adresa")		zip = rsGetUserData("zip")		grad = rsGetUserData("grad")		telefon = rsGetUserData("telefon")		mob = rsGetUserData("mob")	End ifEnd if

Why that code is not working. Why my database table wont update. I get no error, but my table fileds remain the same. Pls help

Link to comment
Share on other sites

I've been writing a system that required me to update fields in a database.I have got mine working now after getting lots of help on here and playing around with the code.Take a look at mine and see if you can find anything that helps.First, the page with the form to make the updates with:

<%Dim adoConDim rsUpdateDim strSQL Dim lngRecordNo lngRecordNo = CLng(Request.QueryString("ID"))Set adoCon = Server.CreateObject("ADODB.Connection") adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("show1.mdb") Set rsUpdate = Server.CreateObject("ADODB.Recordset") strSQL = "SELECT tblSeats.* FROM tblSeats WHERE ID=" & lngRecordNorsUpdate.Open strSQL, adoCon%> <html><head><title>Make Booking</title><style type="text/css"><!--.style8 {font-size: 9px; font-weight: bold; font-family: Verdana, Arial, Helvetica, sans-serif; }--></style><% randomizerandom_number=int(rnd*9)+1%><%RandomizeFor counter = 1 to 5random_number = Int(26 * Rnd + 97)random_letter = Chr(random_number)password = password & random_letterNext%></head><body bgcolor="white" text="black"><!-- Begin form code --><form name="form" method="post" action="show1_makebooking_process.asp"><table border="0" cellspacing="0" cellpadding="0">  <tr>	<td><span class="style8">Seat</span></td>	<td width="10" rowspan="7"> </td>	<td><select name="seat">	  <option><% = rsUpdate("Seat") %></option>	</select>	</td>  </tr>  <tr>	<td><span class="style8">Forename</span></td>	<td><input type="text" name="cust_forename" value="<% = rsUpdate("cust_forename") %>"></td>  </tr>  <tr>	<td><span class="style8">Surname</span></td>	<td><input type="text" name="cust_surname" value="<% = rsUpdate("cust_surname") %>"></td>  </tr>  <tr>	<td><p class="style8">Address</p>	  <p class="style8"> </p></td>	<td><textarea name="cust_address"><% = rsUpdate("cust_address") %></textarea></td>  </tr>  <tr>	<td><span class="style8">Postcode</span></td>	<td><input type="text" name="cust_postcode" value="<% = rsUpdate("cust_postcode") %>"></td>  </tr>  <tr>	<td><span class="style8">Tel Number </span></td>	<td><input name="cust_area_code" type="text" size="5" value="<% = rsUpdate("cust_area_code") %>">	  <input name="cust_tel_number" type="text" size="18" value="<% = rsUpdate("cust_tel_number") %>"></td>  </tr>  <tr>	<input type="hidden" name="status" value="Booked">	<input type="hidden" name="ID" value="<% = rsUpdate("ID") %>"><input type="hidden" name="cust_book_id" value="<%= random_number %><%= password %>"><input type="hidden" name="booked_date" value="<%response.write(date())%>">	<td colspan="3"><input type="submit" name="Submit" value="MAKE BOOKING"></td>	</tr></table></form><!-- End form code --></body></html><%rsUpdate.CloseSet rsUpdate = NothingSet adoCon = Nothing%>

Secondly, the processing page (where the form is sent to)

<%Dim adoCon  Dim rsUpdateEntry  Dim strSQL   Dim lngRecordNo  lngRecordNo = CLng(Request.Form("ID"))Set adoCon = Server.CreateObject("ADODB.Connection")adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("show1.mdb")  Set rsUpdateEntry = Server.CreateObject("ADODB.Recordset")strSQL = "SELECT tblSeats.* FROM tblSeats WHERE ID=" & lngRecordNo rsUpdateEntry.CursorType = 2rsUpdateEntry.LockType = 3rsUpdateEntry.Open strSQL, adoConrsUpdateEntry.Fields("Status") = Request.Form("Status")rsUpdateEntry.Fields("Cust_Forename") = Request.Form("Cust_Forename")rsUpdateEntry.Fields("Cust_Surname") = Request.Form("Cust_Surname")rsUpdateEntry.Fields("Cust_Book_ID") = Request.Form("Cust_Book_ID")rsUpdateEntry.Fields("Cust_Address") = Request.Form("Cust_Address")rsUpdateEntry.Fields("Cust_Postcode") = Request.Form("Cust_Postcode")rsUpdateEntry.Fields("Cust_Area_Code") = Request.Form("Cust_Area_Code")rsUpdateEntry.Fields("Cust_Tel_Number") = Request.Form("Cust_Tel_number")rsUpdateEntry.Fields("Booked_Date") = Request.Form("Booked_Date")rsUpdateEntry.UpdatersUpdateEntry.CloseSet rsUpdateEntry = NothingSet adoCon = Nothing'I HAVE ADDED THIS LINE FOR YOU, IF YOU WANT TO REDIRECT THE USER TO ANOTHER PAGE THEN USE THIS, BUT I AM SHOWING THEIR BOOKING CONFIRMATION INSTEAD'Response.Redirect "your-page-here.asp"%> <html><head><title>Booking Confirmation</title></head><body><font face="verdana" color="#666666">Thank you</font><br><br><font face="verdana" color="#000000">The booking has been made. Please record your reference number.<br><br>Your Unique Reference Number Is: <b><% = Request.Form("Cust_Book_ID") %></b><br><br><br><a href="/default.asp">Click Here To Return To The Show Selector</a></font></body></html>

I hope that helps you :)

Link to comment
Share on other sites

The easiest way to debug a page is to give yourself debugging statements and figure out where the execution is going, and what the values of your variables are. Use response.write to print out things as you go and it will help you determine where the problem is.

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...