Jump to content

Insert into database


choobakka

Recommended Posts

same thing again  :)same thing about not being able to submit date and no change in database

The only thing it said was
Submitting records has been disabled from this demo
thats it??? If you are clicking the save button and getting this result (and using hte exact code provided) then your page is not getting the value of the button you are clicking.
Link to comment
Share on other sites

  • Replies 66
  • Created
  • Last Reply

Top Posters In This Topic

I just noticed an error in the SQL statement

  sql=sql & "Telephone1='" & Request.Form("Telephone1") & "',"    sql=sql & "Telephone2='" & Request.Form("Telephone2") & "',"  <---error here  WHERE tblCustomer.[CustomerID]=" & CustomerID "

Remove the comma (,) after the Request.Form("Telephone2") and add a space

  sql=sql & "Telephone1='" & Request.Form("Telephone1") & "',"    sql=sql & "Telephone2='" & Request.Form("Telephone2") & "' "  WHERE tblCustomer.[CustomerID]=" & CustomerID "

since your code has onerror resume next this means if an error occurs it will continue anyway...so what was probably happening was this error in the sql but hte code just continued on.Try this new sql and see if that works.

Link to comment
Share on other sites

this is the code for the ASP page (view.asp) which extracts all of the data from the table within the database:<%option explicit%><html><head><title>List Database Table</title></head><body><%dim conn,rs,xset conn=Server.CreateObject("ADODB.Connection") conn.provider="Microsoft.Jet.OLEDB.4.0"conn.open(server.mappath("disso1.mdb"))set rs=Server.CreateObject("ADODB.Recordset")rs.open "SELECT * FROM tblCustomer",conn%><h2>List Database Table</h2><p>Click on a button to modify a record.</p><table border="1" width="100%"><tr bgcolor="#b0c4de"><%for each x in rs.Fields response.write("<th>" & ucase(x.name) & "</th>")next%></tr><%do until rs.EOF%><tr bgcolor="#f0f0f0"><form method="post" action="demo_db_edit.asp" target="_blank"><%for each x in rs.Fields if x.name="CustomerID" then%> <td><input type="submit" name="CustomerID" value="<%=x.value%>"></td> <%else%> <td><%Response.Write(x.value)%> </td> <%end ifnext%></form><%rs.MoveNext%></tr><%looprs.closeset rs=nothingconn.closeset conn=nothing%></table></body></html>view.asp also creates buttons for the unique identifiers(customerid) for each record. if i click on any of these buttons i am presented with demo_db_edit.asp:<%CustomerID=Request.Form("CustomerID")if CustomerID="" then response.endset conn=Server.CreateObject("ADODB.Connection") conn.provider="Microsoft.Jet.OLEDB.4.0"conn.open(server.mappath("disso1.mdb"))set rs = Server.CreateObject("ADODB.Recordset")rs.Open "Select * from tblCustomer where tblCustomer.[CustomerID]=" & CustomerID , conn%><html><head><title>Edit DataBase Table</title></head><body><h2>Edit Database Table</h2><form method="post" action="demo_db_submit.asp" target="_blank"><input name="CustomerID" type="hidden" value=<%=CustomerID%>><table bgcolor="#b0c4de"><%for each x in rs.Fields if x.name <> "no" and x.name <> "dateadded" then%> <tr> <td><%=x.name%> </td> <td><input name="<%=x.name%>" value="<%=x.value%>" size="20"></td> <%end ifnextrs.closeconn.close%></tr></table><br /><input type="submit" name="action" value="Save"><input type="submit" name="action" value="Delete"></form></body></html>this page allows me to edit the data for the selected record. i am also presented with a SAVE button and a DELETE button. each of those buttons should either delete or save the data from/into the database. this is done via demo_db_submit.asp:<html><head><title>Submit DataBase</title></head><body><h2>Submit to Database</h2><%on error resume nextset conn=Server.CreateObject("ADODB.Connection") conn.provider="Microsoft.Jet.OLEDB.4.0"conn.open(server.mappath("disso1.mdb"))if Request.form("action")="Save" then CustomerID=Request.Form("CustomerID") sql="UPDATE tblCustomer SET CustomerID="' & Request.Form("CustomerID") & "'," sql=sql & "Last_Name='" & Request.Form("Last_Name") & "'," sql=sql & "First_Name='" & Request.Form("First_Name") & "'," sql=sql & "Address1='" & Request.Form("Address1") & "'," sql=sql & "Address2='" & Request.Form("Address2") & "'," sql=sql & "Address3='" & Request.Form("Address3") & "'," sql=sql & "Post_Code='" & Request.Form("Post_Code") & "'," sql=sql & "Telephone1='" & Request.Form("Telephone1") & "'," sql=sql & "Telephone2='" & Request.Form("Telephone2") & "' " WHERE tblCustomer.[CustomerID]=" & CustomerID "' Response.Write(sql)' Response.Write(" yuppy, we did it! ")' else ' Response.Write("Record number " & CustomerID & " was updated.")' end if Response.Write("Submitting records has been disabled from this demo")end ifif Request.Form("action")="Delete" then CustomerID=Request.Form("CustomerID")' conn.Execute "DELETE FROM tblCustomer WHERE tblCustomer.[CustomerID]=" & CustomerID, Recordsaffected' if err <> 0 then' Response.Write("You do not have permission to delete a record from this database!")' else ' Response.Write("Record number " & no & " was deleted.")' end if Response.Write("Deleting records has been disabled from this demo")end ifconn.close%></body></html>however, when i click on either the SAVE or DELETE button, i am presented with the message saying that i am not able to submit data etc and there is no action taken with regard to the database.

Link to comment
Share on other sites

if the fields "telephone1" and so on are NUMERIC then remove the ' character:

  sql=sql & "Telephone1= " & Request.Form("Telephone1") & ","
is this a mind-buthering post or what ?! :( come on guys, what's wrong with this code?!?! :D let's make a BRAINSTORM :):)
Link to comment
Share on other sites

try using this liners.Open "Select * from tblCustomer where tblCustomer.[CustomerID]=" & CustomerID , connlike thisrs.Open "Select * from tblCustomer where CustomerID = " & CustomerID & "", connI'm guessing now, although it does look a bit suspect

Link to comment
Share on other sites

1. is the DB readonly; do Eeryone group has read/write permissons ?!2. use response.write command to see what data is being sent from the form and thoroughly check it !3. set ALL fields in the table to be TEXT, allow them to be empty and not required! once you've done that, use the ' character in the sql INSERT INTO/UPDATE statementgive it a shot !

Link to comment
Share on other sites

In one of my earlier posts, i have instruced you on how to alow the DB to accept changes. It is a posibility that your DB is ReadOnly or the security group "Everyone" doesn't have the wright to make changes.I thought you've already checked that !

Link to comment
Share on other sites

ASPNETGUY have u managed to run those tests?maybe i should change the IF ELSE statements starting at where the SQL statements begin!

not yet I have been very busy...I am at work most days when posting to this forum so I have to wait for breaks...lolI hope to get it done today. Sorry for the wait.
Link to comment
Share on other sites

remove the last << , >> comma:

 sql="UPDATE tblCustomer SET CustomerID="' & Request.Form("CustomerID") & "'," sql=sql & "Last_Name='" & Request.Form("Last_Name") & "',"sql=sql & "First_Name='" & Request.Form("First_Name") & "',"sql=sql & "Address1='" & Request.Form("Address1") & "',"sql=sql & "Address2='" & Request.Form("Address2") & "',"sql=sql & "Address3='" & Request.Form("Address3") & "',"sql=sql & "Post_Code='" & Request.Form("Post_Code") & "',"sql=sql & "Telephone1='" & Request.Form("Telephone1") & "',"sql=sql & "Telephone2='" & Request.Form("Telephone2") & "',"WHERE tblCustomer.[CustomerID]=" & CustomerID "

 ..."Telephone2='" & Request.Form("Telephone2") & "'"...

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

×
×
  • Create New...