Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_web_howto thread: Server.Mappath


Message #1 by "Lance Kirby" <lkirby@g...> on Fri, 24 May 2002 23:54:56
I am pretty new to ASP and having some trouble i have my web site up and 
running and everything works just fine except for one thing.  My web page 
is my business and I am always taking pictures of my product and putting 
them on the computer which is my web server which is also running SQL 
server 2000.  My problem is is when i go to my e store front to go in and 
modify or add or delete a product which i can get to the i make my 
changes and hit the submit button the browser just hangs there and never 
does anything it just sits there it should return me to the ad, delete, 
and modify page.  Below is my script can anyone just me some help that 
would be great


<% 
	If Session("product")<>"yes" Then
		response.redirect "index.asp"
	End If
%>

<!-- #include file="stdform.asp" -->
<!-- #include file="admininclude.asp" -->
<!-- #include file="upload.asp" -->

<%
function FixQuote(strSource)
	FixQuote = Replace(strSource, "'", "''")
end function

function FixPrice(strSource)
	FixPrice = Replace(strSource, "$", "")
end function

function FixComma(strSource)
	FixComma = Replace(strSource, ",", "")
end function


hadErrors=false

'Response.BinaryWrite(Request.BinaryRead(Request.TotalBytes))
byteCount = Request.TotalBytes
'Response.BinaryWrite(Request.BinaryRead(varByteCount))

if byteCount <> 0 then 'if forn has been filled in

'gather feilds from form
	RequestBin = Request.BinaryRead(byteCount)
	Dim UploadRequest
	Set UploadRequest = CreateObject("Scripting.Dictionary")
	BuildUploadRequest  RequestBin
	name = UploadRequest.Item("name").Item("Value")
	description = UploadRequest.Item("description").Item("Value")
	price = UploadRequest.Item("price").Item("Value")
	catcode = UploadRequest.Item("catcode").Item("Value")
	notes = UploadRequest.Item("notes").Item("Value")
	featured = UploadRequest.Item("featured").Item("Value")
 'Working with image values
	imagecontentType = UploadRequest.Item("image").Item("ContentType")
	imagepathname = UploadRequest.Item("image").Item("FileName")
	image = Right(imagepathname,Len(imagepathname)-InstrRev
(imagepathname,"\"))
	imagevalue = UploadRequest.Item("image").Item("Value")

	strTableName="products"

'	Does it already exist?
	' data test.  Don't allow them to add this record
	' unless all the fields check.
	' In this case only check the Category Name field.

	if trim("name") & "" = "" then
		hadErrors=true
		strError="Please add a value for the product name field."
	end if	

	if hadErrors=false then
		set oRS=db.Execute ("select name from products " &_
			"where name like '%" & fixquote(name) & "%'")
		if not oRS.EOF then
			hadErrors=true
			strError="This product already exists in the 
database."
		end if
		set oRS=Nothing
	end if

	if hadErrors=false then
		set oRS=Server.CreateObject("ADODB.Recordset")
		oRS.CursorType = adOpenKeyset
		oRS.LockType = adLockOptimistic
		oRS.Open strTableName, strConn, , , adCmdTable
		sql = "Insert Into products (name, description, price, "

			if image <> "" then
				sql = sql & "image, "
			end if

			sql = sql & "catcode, notes, featured) "
			
			sql = sql & "Values ('" & fixquote(name) & "', "
			sql = sql & "'" & fixquote(description) & "', "
			sql = sql & "'" & fixcomma(fixprice(price)) 
& "', "

			if image <> "" then
				sql = sql & "'" & image & "', "
			end if	

			sql = sql & "'" & catcode & "', "
			sql = sql & "'" & fixquote(notes) & "', "
			sql = sql & "'" & featured & "'"
			sql = sql & ")"
			db.execute sql
			
			'Create FileSytemObject Component
			 Set ScriptObject = Server.CreateObject
("Scripting.FileSystemObject")
			'Create and Write to a File

			 if image <> "" then
				'Create and Write to a File
				 Set MyFile = ScriptObject.CreateTextFile
(Server.MapPath("/images/products/"&image))
				 
				 For intCount = 1 to LenB(imagevalue) 
				     MyFile.Write chr(AscB(MidB
(imagevalue,intCount,1)))
				 Next 
				 MyFile.Close 
			 end if

		if db.Errors.Count > 0 then
			hadErrors=True
			strError="<h3>Database errors occurred.</h3>"
			for each e in oConn.Errors
				strError=strError & e.Description & "<br>"
			next
		end if

	end if

	end if

if hadErrors=false then

response.redirect "prodmanager.asp"

else %>

<h1>Data Error</h1>
<p><% =strError %></p>
<% end if %>



  Return to Index