Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: adding and editing records to a database


Message #1 by "Gary Cappelletti" <gacapp@a...> on Thu, 10 Oct 2002 14:16:11
Can some one out there help me???

I am in chapter 10 of Beginning ASP Databases and I am trying to use the 
code for editing and adding records to a database.  

I think the code is working right except that I can't get the Try-It-Out-
2.asp page to show what was inserted into my database.  After I fill out 
the form, I get a blank page.  So I go to View and view the source code 
and there it says that my records were inserted into the database, but not 
on my web page.

I copied the code word for word, except I substituted my database info for 
the example.

Can someone tell me how I can get the information to show on my web page??

Any help would be greatly appreciated.

Gary
Message #2 by "Timothy M. Straub" <tim@r...> on Thu, 10 Oct 2002 14:48:17
Gary - 

A couple questions....

(1) I am assuming you can see the text "Try it Out #2....." that is just 
the plain HTML at the top of the page.  Is this correct?

(2) Does your record get stored in the database?

Also you can always try to use response.write to write the variables to 
the page before you get to the end of the page.  ie. write out the 
strInsert and strValues after each field to see if the variable is being 
filled correctly.  I usually like to add in text/numbers with the 
variable just so I can see something in case the variable is null.

If you still have problems, throw some code up here and I'll give it a 
look to see if I can help.

Thanks,
-Tim


> Can some one out there help me???

> I am in chapter 10 of Beginning ASP Databases and I am trying to use 
the 
c> ode for editing and adding records to a database.  

> I think the code is working right except that I can't get the Try-It-
Out-
2> .asp page to show what was inserted into my database.  After I fill 
out 
t> he form, I get a blank page.  So I go to View and view the source code 
a> nd there it says that my records were inserted into the database, but 
not 
o> n my web page.

> I copied the code word for word, except I substituted my database info 
for 
t> he example.

> Can someone tell me how I can get the information to show on my web 
page??

> Any help would be greatly appreciated.

> Gary
Message #3 by "Gary Cappelletti" <gacapp@a...> on Sun, 13 Oct 2002 15:38:51
Tim,
  Well I can't see the wording inside the <BODY> tag.  I still get a blank 
page and I'm not sure why.  The information is being put into my table, so 
that is working.

Here is the code for my page and hopefully you can tell me why it isn't 
showing on my web page.

Thank you.
Gary


<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft FrontPage 4.0">
<TITLE>Add Record to Event Table<TITLE>
</HEAD>
<BODY>
Event Added To Table<br>

<%
'Declare variables needed
Dim strInsert
Dim strValues
Dim adCmdText
Dim blnCriticalError

'Set required variables
adCmdText = 1
	
'***********************************************************
'* If an Add was requested, add the new club to the database
'***********************************************************
If Request.Form("Action") = "Add" Then
	
	'Start building the SQL strings with the required fields
	strInsert = "Insert into Events (Event_Name,Location"
	strValues = "Values('" & CStr(Request.Form("txtEvent_Name")) & _
		"','" & CStr(Request.Form("txtLocation")) & "'"
		
	
	'Add city if present
	If Len(Request.Form("txtCity")) > 0 Then
		'Add the column name to the insert string
		strInsert = strInsert & ",City"
		'Add the value to the value string
		strValues = strValues & ",'" & _
			Cstr(Request.Form("txtCity")) & "'"
	End If

	'Add state if present
	If Len(Request.Form("txtState")) > 0 Then
		'Add the column name to the insert string
		strInsert = strInsert & ",State"
		'Add the value to the value string
		strValues = strValues & ",'" & _
			Cstr(Request.Form("txtState")) & "'"
	End If

	'Add zip if cheked
	If Len(Request.Form("txtZip_Code")) > 0 Then
		'Add the column name to the insert string
		strInsert = strInsert & ",Zip_Code"
		'Add the value to the value string
		strValues = strValues & ",'" & _
		Cstr(Request.Form("txtZip_Code")) & "'"
	End If

	'Add description if present
	If Len(Request.Form("txtDescription")) > 0 Then
		'Add the column name to the insert string
		strInsert = strInsert & ",Description"
		'Add the value to the value string
		strValues = strValues & ",'" & _
			Cstr(Request.Form("txtDescription")) & "'"
	End If

'Add start date if present
	If Len(Request.Form("txtStart_Date")) > 0 Then
		'Add the column name to the insert string
		strInsert = strInsert & ",Start_Date"
		'Add the value to the value string
		strValues = strValues & ",'" & _
			Cstr(Request.Form("txtStart_Date")) & "'"
	End If

'Add end date if present
	If Len(Request.Form("txtEnd_Date")) > 0 Then
		'Add the column name to the insert string
		strInsert = strInsert & ",End_Date"
		'Add the value to the value string
		strValues = strValues & ",'" & _
			Cstr(Request.Form("txtEnd_Date")) & "'"
	End If



	'Add time if present
	If Len(Request.Form("txtTime")) > 0 Then
		'Add the column name to the insert string
		strInsert = strInsert & ",Time"
		'Add the value to the value string
		strValues = strValues & ",'" & _
			Cstr(Request.Form("txtTime")) & "'"
    End If
    
    'Add phone if present
	If Len(Request.Form("txtPhone")) > 0 Then
		'Add the column name to the insert string
		strInsert = strInsert & ",Phone"
		'Add the value to the value string
		strValues = strValues & ",'" & _
			Cstr(Request.Form("txtPhone")) & "'"
    End If

	'Add website if present
	If Len(Request.Form("txtWebsite")) > 0 Then
		'Add the column name to the insert string
		strInsert = strInsert & ",Website"
		'Add the value to the value string
		strValues = strValues & ",'" & _
			Cstr(Request.Form("txtWebsite")) & "'"
    End If

	'Add email if present
	If Len(Request.Form("txtEmail")) > 0 Then
		'Add the column name to the insert string
		strInsert = strInsert & ",Email"
		'Add the value to the value string
		strValues = strValues & ",'" & _
			Cstr(Request.Form("txtEmail")) & "'"
    End If

	'Add image path if present
	If Len(Request.Form("txtevent_image")) > 0 Then
		'Add the column name to the insert string
		strInsert = strInsert & ",event_image"
		'Add the value to the value string
		strValues = strValues & ",'" & _
			Cstr(Request.Form("txtevent_image")) & "'"
    End If


	'Create and open the database object
	Set objConn = Server.CreateObject("ADODB.Connection")
	objConn.Open "DSN=Businesses"

	'Create the command object
	Set objCmd = Server.CreateObject("ADODB.Command")

	'Set the command object properties
	Set objCmd.ActiveConnection = objConn
	objCmd.CommandText = strInsert & ") " & strValues & ")"
	objCmd.CommandType = adCmdText

	'Execute the command
	objCmd.Execute
		
	'Display the insert string
	Response.Write "The following insert string was executed and " & _
		"the values inserted into the Events table.<P>"
	Response.Write strInsert & ") " & strValues & ")"
	
End If

'Close and dereference database objects
Set objCmd = Nothing
objConn.Close
Set objConn = Nothing
%>

</BODY>
</HTML>











Message #4 by "Timothy M. Straub" <tim@r...> on Mon, 14 Oct 2002 18:57:18
Gary - 

It looks like the closing tag for <title></title> is missing the back-
slash.  So it may put everything into the title and not the body.

Try that.  Hope it works.  Let me know.

-Tim

  Return to Index