If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Understanding the concept of merging ASP ans SQL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-19-05, 08:46
JJ7AS JJ7AS is offline
Registered User
 
Join Date: Jan 2005
Posts: 9
Understanding the concept of merging ASP ans SQL

hi guys,

This might sound like a silly problem, i kinda understand whats going on in the following statement, but i am using dreamweaver as my authoring tool(dremaweaver tends to add things that are not always needed i find) and it derived the code automatically when clicking an "insert record" option.
Could anyone please re-write or help me understand what is being implemented here in dummy terms or so i can re-write it myself?!
Any help would be greatly appreciated - Im confused .
thank you.



<%
' *** Edit Operations: declare variables

Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId

Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" & Request.QueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables

If (CStr(Request("MM_insert")) = "form2") Then

MM_editConnection = MM_Wortons_Notification_db_STRING
MM_editTable = "NOTIFICATION"
MM_editRedirectUrl = "Registration.asp"
MM_fieldsStr = "selectnature|value|title|value|commenttxt|val ue"
MM_columnsStr = "Notification_Type|',none,''|Notification_Descript ion|',none,''|Notification_Comment|',none,''"

' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")

' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
Next

' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If

End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it

Dim MM_tableValues
Dim MM_dbValues

If (CStr(Request("MM_insert")) <> "") Then

' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),",")
MM_delim = MM_typeArray(0)
If (MM_delim = "none") Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none") Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none") Then MM_emptyVal = ""
If (MM_formVal = "") Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End If
MM_tableValues = MM_tableValues & MM_columns(MM_i)
MM_dbValues = MM_dbValues & MM_formVal
Next
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"

If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If
%>
Reply With Quote
  #2 (permalink)  
Old 02-24-05, 06:23
nayder nayder is offline
Registered User
 
Join Date: Feb 2005
Location: England
Posts: 2
hmmm

it seem this code was automatically generated by dreamweaver. Im not 100% sure but it looks like its code to add a record to a database. There is a an horriffic amount of extra code that is not needed for such an operation.

What is it u want to do exactly, bulid a user registration form of some sort?
Reply With Quote
  #3 (permalink)  
Old 02-24-05, 09:23
RhythmAddict RhythmAddict is offline
Registered User
 
Join Date: Dec 2003
Posts: 148
I think using the drag-drop style dreamweaver code actually makes ASP seem a lot more difficult than it actually is. Personally, i see the MM_'s and I freak out and don't even want to look at what's going on there.
Reply With Quote
  #4 (permalink)  
Old 02-24-05, 12:58
JJ7AS JJ7AS is offline
Registered User
 
Join Date: Jan 2005
Posts: 9
Quote:
Originally Posted by nayder
it seem this code was automatically generated by dreamweaver. Im not 100% sure but it looks like its code to add a record to a database. There is a an horriffic amount of extra code that is not needed for such an operation.

What is it u want to do exactly, bulid a user registration form of some sort?

Sorry for the late reply, yes i am tring to write a users registration details to my database using my own code. It smore difficult trying to work out what Dreamweaver is doing at each line!! Any ideas on how to do a registration page?
Thanks.
Reply With Quote
  #5 (permalink)  
Old 02-28-05, 01:51
richy240 richy240 is offline
Registered User
 
Join Date: Sep 2003
Posts: 24
What the *#$%@&?!?

I love Dreamweaver for HTML and the like, but I've never used to for ASP - now I'm glad for that. What a mess! I've seem their JavaScript and it looks a lot like this. That is, the "MM_" is in front of EVERYTHING and the code is very confusing. (I am starting to think that is their plan!)

There're lots of resources for executing INSERT statements in ASP. They are just like UPDATE and DELETE statements, as far as the ASP code is concerned. (Of course, the SQL is different.)

Here is my code for registering a new user. Listed below you'll find ONLY the code to execute the INSERT statement. I also check for duplicate usernames and a couple other things...

Code:
If execute_insert Then
	  Dim register_cmd, show_email
	  show_email = False
	  
	  If Request.Form("SHOW_EMAIL") = "On" Then
	    show_email = True
	  End If
	
	  Set content_db = Server.CreateObject("ADODB.Connection")
	  Set register_cmd = Server.CreateObject("ADODB.Command")
	
	  sqlStr = "INSERT INTO tb_members (member_handle, member_password, email_addr, web_addr, geo_location, show_email, admin_level) VALUES ('" & Request.Form("MEMBER_HANDLE") & "', '" & Request.Form("PASSWORD1") & "', '" & Request.Form("EMAIL_ADDR1") & "', '" & Request.Form("WEB_ADDR") & "', '" & Request.Form("LOCATION") & "', " & show_email & ", 4);"
	
	  content_db.Open connection_str
	
	  Set register_cmd.ActiveConnection = content_db
	
	  register_cmd.CommandText = sqlStr
	  register_cmd.CommandType = 1
	
	  register_cmd.Execute
	
	  content_db.Close
	
	  Set register_cmd = Nothing
	  Set content_db = Nothing
End If
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On