Jump to content
Sign in to follow this  
choobakka

Insert into database

Recommended Posts

i have followed the ADO tutorials on this site and im upto the last part. i would like to insert the changes made into the database.<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 "' conn.Execute sql, Recordsaffected' if err <> 0 then' Response.Write("You do not have permission to update this database!")' else ' Response.Write("Record number " & no & " 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>it is the last part (in red) which i am having difficulty with. everthing else works fine. i simply want the save and delete buttons to work. thanks in advance

Share this post


Link to post
Share on other sites

the line that actually executes the delete staement is commented out.Is the exact code that you cannot get to work????If so un comment the delete staement and let us know if it works or what errors you get.

Share this post


Link to post
Share on other sites

everything upto the red code works. when i click on the save and delete buttons, the code is executed but i get a messaage saying that updating and deleteing is not allowed (ie i dont have the permission). all i need is to be able to get the Save and Delete buttons to execute successfully (ie Save or Delete from the database. at the moment, this is not the case.

Share this post


Link to post
Share on other sites

please post the page that contains the 2 buttons then...I need to see the code that sends the querystring 'action'

Share this post


Link to post
Share on other sites

The code with the 2 buttons is below:<%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>

Share this post


Link to post
Share on other sites

On the 2nd page place this piece of code as the first line in your ASP code..

Response.Write(Request.Form("action"))

This will show what values are really being sent as action. Click both buttons and post the values you get for each

Share this post


Link to post
Share on other sites

I get the same messages as before.for the save button:Submit to DatabaseSubmitting records has been disabled from this demo for the delete button:Submit to DatabaseDeleting records has been disabled from this demo a new window opens which means that the buttons are executing to some extent. it is simply not INSERTING or DELETING from the database. maybe i am missing some code!

Share this post


Link to post
Share on other sites

Do the records get deleted or not ?!?!if not: 1. try naming the buttons save/delete... 2. see if user "everyone" has the read/write capability for the database ! 3. check readonly attributes for that database or the containing folder...see what happens...

Share this post


Link to post
Share on other sites

If you yourself go to the ADO demp page: http://www.w3schools.com/ado/ado_demo.aspclick on the link which says "List, edit, update, and delete database records"you are presented with the first ASP page.then click on any of the buttons within the table. this takes you to the second ASP page.on this page you are able to edit the current database data.THIS IS THE STAGE THAT I AM AT.if you then click on SAVE or DELETE you get a page that either says:Submit to DatabaseSubmitting records has been disabled from this demo orSubmit to DatabaseDeleting records has been disabled from this demo.this is exactly what i get when i click on the buttons.below is the code i have for the ASP page once either of the buttons is pressed:<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 "' conn.Execute sql, Recordsaffected' if err <> 0 then' Response.Write("You do not have permission to update this database!")' else ' Response.Write("Record number " & no & " 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>this ASP page however only results in either of the two messages mentioned above and there is no interaction with the database once either button is pressed.

Share this post


Link to post
Share on other sites

dude, are u doing this on localhost or a server of your own? or are you doing it from their server?! maybe the database is readonly or there is a write privelledge needed.the code should work as it is!do this on your pc. insltall IIS and run it for your self

Share this post


Link to post
Share on other sites

is the drive with the database ntfs or fat32 ?!if it is ntfs, right click the folder containing the database and select "security" - "add..." - "advanced" - "find now" an then look for the group called "everyone" ! then click OK to the previous windows to confirm the addmition until you get back to the properties window.click "everyone" (the group that you have just added) and then sellect "full control".try it like this, see what happends.oh, if the partition table is fat32, I donnow how to do it :)

Share this post


Link to post
Share on other sites

it is NTFS. when i rightclick the folder the only things that says security is 'sharing and security'. if i select this i get a window with 4 tabs - general, sharing, web sharing, and customize. is this correct and if so what do i do next?

Share this post


Link to post
Share on other sites

in any windows explorer window in the TOOLS menu click "Folder Options" -> VIEW -> and the last one on the list should be "Use simple file sharing..." = Uncheck that!then try again as i've instructed you in my previous postkeep in touch

Share this post


Link to post
Share on other sites

have a look:

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("Submitting records has been disabled from this demo")end if
IT IS NORMAL TO SAY THAT !! but it does not mean it !!! oh, man...give it a shot like this:
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(" yuppy, we did it !!")else  Response.Write("Submitting records has been disabled from this demo")end if

Share this post


Link to post
Share on other sites

im aware of that lol. but even after a submit button is pressed, nothing changes in the database. that is my main gripe. im not worried about the message afterwards. its the inputting into the database which aint working!

Share this post


Link to post
Share on other sites
i replaced the first response.write with the response.write(sql). same result  :)  could my SQL statements be wrong?

They wanted you to post the results of the above staement that way they could see exactly what sql statement is being executed and to see if infact the sql is wrong

Share this post


Link to post
Share on other sites

do this and then copy and paste whatever is displayed in your browser to a post.

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("Submitting records has been disabled from this demo")end if

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