Jump to content

Problems with adding record in a database


steveaj

Recommended Posts

I have problem adding a record into my database from a web browser. I have written the html page and the action page as follows;Here is the form code:<html><body><form method="post" action="demo_add.asp"><table><tr><td>S/No:</td><td><input name="id"></td></tr><tr><td>Name:</td><td><input name="name"></td></tr><tr><td>Phone Number:</td><td><input name="foneno"></td></tr></table><br /><br /><input type="submit" value="Submit"><input type="reset" value="Reset"></form></body></html>and here is the form action code (demo_add.asp):<html><body><%set conn=Server.CreateObject("ADODB.Connection")conn.Provider="Microsoft.Jet.OLEDB.4.0"conn.Open "C:\Inetpub\wwwroot\My_Web\Example\Contacts.mdb"set rs=Server.CreateObject("ADODB.recordset")sql="INSERT INTO Phone_Numbers (id,name,"sql=sql & "foneno)"sql=sql & " VALUES "sql=sql & "('" & Request.Form("id") & "',"sql=sql & "'" & Request.Form("name") & "',"sql=sql & "'" & Request.Form("foneno") & "')"on error resume nextconn.Execute sql,recaffectedif err<>0 thenResponse.Write("No update permissions!")elseResponse.Write("<h3>" & recaffected & " record added</h3>")end ifconn.close%></body></html>Each time I try to add a record from the browser, it would retrurn the error message (No Update Permission).Please I want folks to help me look carefully at the code and tell me all the possible errors in the code. Thanks

Link to comment
Share on other sites

Please I am in a great confusion here right now. Please if you will assist me; write a code to access an ms database called "Contacts" with a table called "Phone_Numbers" with three fields named; id, name and foneno. None of the fields is a primary key (Or is that the error?). So, ignoring my own code completely, write a code to add a record to that database assuming the database is located in C:\Inetpub\wwwroot\My_Web\Example\Contacts.Please I am very sorry if I am asking for so much but I would be glad if you do.

Link to comment
Share on other sites

The code you have is fine. You may want to define recaffected before using it though. Other than that, take the suggestions to print out error details. It's not easy to fix something when you don't know what the problem is. The information is there to tell you what the problem is, but you're not using it.

Link to comment
Share on other sites

HiYou are using a Access database, aren't you ?On this data base do you have the ID on autonumber? If not change it to auto number then you may be adding the record over one that already exists.If you do not What to change to auto number you may need to do:1) Run a Query with the SQL code:SELECT ID FROM Phone_Numbers ORDER BY ID DESC2) With this result (exemple ID = 32 ) add one unitID = ID +133 = 32 +13) Run your query with the new ID number Hope it HelpsFilipe

Link to comment
Share on other sites

Thanks everybody. I am grateful Justsomeguys. Based on your suggestions, I removed the code line; on error resume next and the error report I got is; "Microsoft JET Database Engine (0x80004005)Operation must use an updateable query." pointing to the line where I typed; "conn.Execute sql,recaffected" I think it is that line of code that is causing the error or can it be that there is something wrong with the database? I have edited the code several times and what I now have is the database name is still Contacts.mdb, the table is now called PhoneNum, the fields are Id, Name, PhoneNo and everything reflected accurately in the demo_add.asp page. What do you think I might have done with the database? How can I correct the line of code "conn.Execute sql,recaffected"? Is there any way I can skip that line or what is the appropriate code I can type there?I would be happy if I can get your reply again soon.Thanks and God bless

Link to comment
Share on other sites

Yeah I think I can get some help here. Let me now carefully study it. God bless you Just some guys. I would still return to you. If I still get error messages, I would come back to you and if not, I would come back to say thank you. Right now, I want to go and sleep and when I am back tomorrow, I would now work with the article you forwarded to me. Please do help me to make sure it is still available on that web page.

Link to comment
Share on other sites

Please do help me to make sure it is still available on that web page.
I'm not quite sure how I can do that, I'm not the internet.If you're having problems with your query, print it out so you can see what you're sending to the server.
Link to comment
Share on other sites

I'm not quite sure how I can do that, I'm not the internet.If you're having problems with your query, print it out so you can see what you're sending to the server.
Just some Guys!!! You are a great guy indeed. You solved my problems and I am grateful. God will also solve your own problems by his grace. What I meant by making sure it is available on the web is that I thought the page was from your own web site, and you know people keep editing their web pages everyday and I was afraid you may want to remove a content for the other so I wanted to make sure you left the content of that web page for me at least just for one day but whaoo!!! upon testing the code once again carefully, I got my problems solved. Thanks so much for all your efforts so far. Please be sure I would also refer other problems to you if they arise.You are great and great is your potentials.I Love You.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...