Jump to content
Sign in to follow this  
choobakka

Insert into database

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
yes thats it. thats the only message (and action) thats happening."your page is not getting the value of the button you are clicking."please explain.

ignore that and look at the next post I made...I am pretty sure that has been the issue all along

Share this post


Link to post
Share on other sites

If you posted the full code for this page and the page with the submit buttons I will try and run some tests. This is very bizarre behavior...I will have to see it for myself.

Share this post


Link to post
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.

Share this post


Link to post
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 :):)

Share this post


Link to post
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

Share this post


Link to post
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 !

Share this post


Link to post
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 !

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

I am having trouble getting hte asp pages to run...I have ASP.Net installed...I don't know if that is interferring or not. I am frustrated :)

Share this post


Link to post
Share on other sites

INSERT is only used to add new records to the database...are you trying to add a new record or update an existing one???

Share this post


Link to post
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") & "'"...

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...