Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Editing database

Status
Not open for further replies.

Manic

Programmer
Feb 28, 2001
343
GB
I am looking for some code to creat a page (or two pages)to add, edit or delete data in a database.

I have a page set up to view the data in there but I need to be able to editi it using forms, basicly for ease of use.

Anyone have any code ideas?

Manic -----------------------------
I've broken it again !!
-----------------------------
 
There are alot of different ways to do this. With such a broad question, you'd probably be better served to check out this page... look at the entry on updating/edit records. There are a lot of great tutorials on this site that can probably more thoroughly answer your question than could be done here.

 
thanks I will have a look

Manic -----------------------------
I've broken it again !!
-----------------------------
 
Had a quick look but still canno't find what I am looking for.


What I have is a page that pulls data fron the database.

What I need is a page that pulls in all of the data in such a way (a form ?) that I can edit and delete it.

I also need a page that allows me to add data to the database (form based ?)

I had done something simple for this ages ago but I haven't got the resources I used to.

Manic -----------------------------
I've broken it again !!
-----------------------------
 
It's just such a broad question, but I'll give it a shot --

I'll assume that you know how to make recordsets, get data out of them -- be sure to set the proper lockType and cursorType enum's when you have one that you want to update.

<form name=updateForm action=&quot;thisPage.asp&quot; method=post>
<input type=text name=id value=<%=rs(&quot;PKField&quot;)%> readOnly>
<input type=text name=empName value=<%rs(&quot;empName&quot;)%>>
<input type=text name=address value=<%=rs(&quot;address&quot;)%>>
<input type=hidden name=action>
<input type=button value=&quot;Update&quot; onClick=&quot;submitMe('update')>
<input type=button value=&quot;Delete&quot; onClick=&quot;submitMe('delete')>
</form>

So now you have a form, which is initially filled in with a record from the database. It has a readonly field (you might choose to make that just regular html output so as not to tempt users to change it -- and then set another hidden field to the primary key) that contains your primary key id field so you know what record to deal with when you get to the action part of this operation.

You also have that hidden field up there called action... you will check the value of that element when it's time to decide whether to update or delete the current record...

So, now you need a javascript function that will do two things: set the value of the action field, and then submit the form.

<script language=javascript>
function submitMe(value){
if (value == 'update')
document.updateForm.action.value = 'update';
else
document.updateForm.action.value = 'delete';
document.updateForm.submit();
}
</script>

So done -- then on your receiving page (maybe it could be a recursive call to the same page) you would start off by asking for two variables: action, and id

<%
dim action, id
action = request.form(&quot;action&quot;)
id = request.form(&quot;id&quot;)
%>

and then you would get yourself a new recordset (the same one you had before) -- find the record in question, and then do whatever you are supposed to do with it:

<%
dim findString, empName, address
findString = &quot;PKField = &quot; & id
rs.find findString
if action = &quot;delete&quot; then
rs.delete
else
empName = cstr(request.form(&quot;empName&quot;))
address = cstr(request.form(&quot;address&quot;))
rs(&quot;empName&quot;) = empName
rs(&quot;address&quot;) = address
end if
rs.update
%>

and on and on and on --

does this help? :)
Paul Prewett
 
thanks it helped a lot.

I have most of it done now.

Manic -----------------------------
I've broken it again !!
-----------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top