|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
ASP.Net/AJAX - Creating a Page?
Hi my name is Matthew, this is my first time on this forum and you all seem so smart and fast to answer so I thought I would ask a quick question. Please feel free to move this to the appropriate area if necessary!
My question is: I am creating a Content Managment System in .ASP and Microsoft Database 2003. I I have got down how to add text to database and delete text from database (and of course show text from data base), but I cant seem to figure out how to edit text that is currently in the database (while on the website). Any help would be greatly appreciated. (currently I have to delete the record and re add it witch can be very time consuming.) Also I am trying to figure out how to add a new page to the website. With out having a url like the following domain/pages.asp?PageId=01 I would like it to look like this domain/Page_01 Any help would be great fully appreciated. |
|
#2
|
||||
|
||||
|
Quote:
Welcome. Quote:
Well, without seeing any code, I am going to guess you are adding text with an SQL INSERT statement and deleting it with a DELETE statement. The next one you want to look at is the UPDATE statement. Do a query, display the fields of the record you are interested in by prepopulating some form elements, edit the values in the form elements, let your form action hit an asp page that has an update statement. Look through this: http://www.codefixer.com/tutorials/news_management_system_part1.asp probably part 7 for you. |
|
#3
|
|||
|
|||
|
I posted the whole code for my AnnouncmentAdmin.asp page
all my scripting for the add and delete is held in this page but im really not sure what you mean be the update statement. At times I have as many as 10 announcements can I edit them all or just one? And also if you need to know I use microsoft access 2003 databases .mde or .mdb Quote:
|
|
#4
|
|||
|
|||
|
You're missing a lot here. I can't really explain in detail because there's simply too much to cover, go over some tutorials on recordsets and updating an database.
The concept is like this. You pull out information from the database, then display it in a form. Then the user can edit the information in the form, and submit the page, the page then UPDATES the database, replacing the old information with the new ones. You can do multiple edits in one page yes, but first make sure that you have all of the basics down. You should also consider security and try to prevent unsafe characters. It's hard developing a content management system when you're just starting to code. Good luck anyways. You can always get all of the help you want on here. =) |
|
#5
|
|||
|
|||
|
I'm not really sure what you mean by I am missing a lot? And I also don't understand why you think I am a beginner Programmer. Since most of you and most tutorials tell people to do what I have written in 1 page in 4 pages so....
I think I have a pretty good Idea on how to do this thank you all for the help. Quote:
|
|
#6
|
||||
|
||||
|
Glad we could be of assistance.
|
|
#7
|
|||
|
|||
|
Good luck with your project. =)
Just as a reminder, be sure to check for bugs and prevent hackers... |
|
#8
|
||||
|
||||
|
Quote:
the fact you are a new to the forum and you asked a basic question that most experienced programmers would know - how to update a database the demo is based on mikes post... you get a stylesheet, full html code, hyperlinks, a (display, add, update, delete form), and code to (add, delete,update)...all rolled into ONE page...not 4 demo: click me Code:
<html>
<head>
<style>
body {text-align:center;font-family:arial;font-size:12px;}
table {width:400px;font-size:12px;border:1px solid #333;}
input.box {width:100%;font-size:12px;}
td {background:#FCFCFC;border:1px solid #EDEDED;}
td.add {padding:5px;}
td.ck {text-align:center;}
th {background:#333;color:white;padding:2px;}
caption {text-align:left;font-weight:bold;font-size:14px;}
</style>
</head>
<body>
<%
sAction = Request.Form("action")
sLink = Request.QueryString("type")
sAct = Request.Form("act")
sAIDs = Trim(Replace(Request.Form("aid")," ",""))
sPage = Request.ServerVariables("SCRIPT_NAME")
aLinks = Array("Add","Delete","Update","Display")
Function ReturnRS
Set oRs = oConn.Execute("SELECT * FROM tAs;")
If Not oRs.EOF Then ReturnRS = oRs.GetRows
End Function
Function SanitizeString(sString)
If Len(sString) > 0 Then
SanitizeString = Trim(Replace(sString,"'","''"))
End If
End Function
Function OpenDatabase
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("db/ats.mdb") & ";"
End Function
Dim oConn
OpenDatabase
For each item in aLinks
Response.Write "<a href=""" & sPage & "?type=" & item & """>" & item & "</a> "
Next
If Len(sAction) > 0 Then
Select Case sAction
Case "Add"
oConn.Execute("INSERT INTO tAs (Act) VALUES('" & SanitizeString(sAct) & "');")
Case "Delete"
oConn.Execute("DELETE * FROM tAs WHERE AID IN (" & sAIDs & ");")
Case "Update"
For each item in Request.Form
sAct = Request.Form(item)
iAID = Replace(item,"a_","")
If Left(item,2) = "a_" Then
oConn.Execute("UPDATE tAs SET Act='" & SanitizeString(sAct) & "' WHERE AID=" & iAID & ";")
End If
Next
End Select
End If
aActs = ReturnRS
bRS = isArray(aActs)
If sLink = "" Then sLink = "Display"
If bRS OR sLink = "Add" Then
Response.Write "<form action=""" & sPage & """ method=""post"">" & _
"<table><caption>" & sLink & " Form</caption></tr>"
Select Case sLink
Case "Add"
Response.Write "<tr><th colspan=""2"">Announcement</th></tr>" & _
"<tr><td class=""add""><input class=""box""name=""act""></td></tr>" & _
"<tr><td class=""add"" align=""center""><input type=""submit"" name=""action"" maxlength=""50"" value=""Add""></td></tr>"
Case "Delete"
Response.Write "<tr><th>Announcement</th><th>Select</th></tr>"
For i = 0 to UBound(aActs,2)
Response.Write "<tr><td>" & aActs(1,i) & "</td>" & _
" <td class=""ck""><input name=""aid"" type=""checkbox"" value=""" & aActs(0,i) & """></td>" & _
"</tr>"
Next
Response.Write "<tr><td colspan=""2"" align=""center""><input type=""submit"" name=""action"" value=""Delete""></td></tr>"
Case "Update"
Response.Write "<tr><th>Announcement</th></tr>"
For i = 0 to UBound(aActs,2)
Response.write "<tr><td><input class=""box"" name=""a_" & aActs(0,i) & """ value=""" & aActs(1,i) & """></td></tr>"
Next
Response.Write "<tr><td align=""center""><input type=""submit"" name=""action"" value=""Update""></td></tr>"
Case Else
Response.Write "<tr><th>Announcements</th></tr>"
For i = 0 to UBound(aActs,2)
Response.Write "<tr><td>" & aActs(1,i) & "</td></tr>"
Next
End Select
Response.Write "</table></form>"
Else
Response.Write "<h3>No records</h3>"
End If
%>
</body>
</html>
__________________
Please give respect to those that helped solve an issue by clicking on the reputation icon
Last edited by keep_it_simple : March 25th, 2009 at 02:19 AM. Reason: added demo |
![]() |
| Viewing: ASP Free Forums > Programming > ASP Development > ASP.Net/AJAX - Creating a Page? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|