sandhya.o.k
02-22-2007, 06:26 AM
i am new to asp and no idea about image upload ,so i followed one tutorial from stardeveloper.com which is written by faisel khan. That code is working fine,. but now my html form have one listbox control where the user can select multiple values,In this case when the user select more than one value in the list item my code is not working. and i have no idea about what modification have to be done . any suggestions.
or is there any other way for doing the same. any other tutorials?.
i am posting my code here.
This is my html form
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="JavaScript" type="text/javascript">
<!--
function checkform ( form )
{
if (form.txtName.value == "") {
alert( "Please enter your name " );
form.txtName.focus();
return false ;
}
if (form.txtEmail.value == "") {
alert( "Please Enter your Email Address " );
form.txtEmail.focus();
return false ;
}
if (form.lstDescription.value == "") {
alert( "Please Select Project Description " );
form.lstDescription.focus();
return false ;
}
return true ;
}
//-->
</script>
</head>
<body>
<form method="POST" enctype="multipart/form-data" action="insert_request_quote.asp" onsubmit="return checkform(this);">
<table width="472" border="1">
<tr valign="top">
<td width="279" class="style2">Your name <font color="red">*</font><br /></td>
<td width="254"><input class="inputbox" maxlength="50" size="35"
name="txtName" /></td></tr>
<tr valign="top">
<td class="style2">Your email address <font color="red">*</font><br /></td>
<td><input class="inputbox" maxlength="50" size="35"
name="txtEmail" /></td>
</tr>
<tr valign="top">
<td><span class="style2">Please select to best describe this project <font
color="red">*</font><br />
</span><span class="style13"><small>Use the CTRL key to select all that apply</small></span></td>
<td><select multiple="multiple" size="6"
name="lstDescription">
<option value="">-------- Select all that apply ---------</option>
<option
value="Develop a new site">Develop a new site</option>
<option
value="Redesign an existing site">Redesign an existing site</option>
<option
value="Subcontract web design or programming">Subcontract design or programming</option>
<option
value="Make existing site accessible (ADA)">Make existing site accessible (ADA)</option>
<option
value="Make existing site multilingual">Make existing site multilingual</option>
<option value="other (specify below)">Other (specify below)</option>
</select></td>
</tr>
<td class="style2">You can upload a spec document, file or image from your computer</td>
<td><input class="inputbox" type="file" size="30"
name="uploads" /></td>
<tr>
<td height="50" align="middle"> </td>
<td height="50" align="middle">
<div align="left">
<input class="command_button" type="submit" value="Submit" name="submitbt" />
<img
height="8" alt=""
src="Custom quote - the best prices on web site design from India_files/blank.gif"
width="20" border="0" />
<input name="reset" type="reset" class="command_button" value="Reset" />
</div></td></tr>
</table>
</form>
</body>
</html>
THis is my asp code
<% ' insert_request_quote.asp %>
<!--#include file="Loader.asp"-->
<%
Response.Buffer = True
' load object
Dim load
Set load = new Loader
' calling initialize method
load.initialize
' File binary data
Dim fileData
fileData = load.getFileData("uploads")
' File name
Dim fileName
fileName = LCase(load.getFileName("uploads"))
' File path
Dim filePath
filePath = load.getFilePath("uploads")
' File path complete
Dim filePathComplete
filePathComplete = load.getFilePathComplete("uploads")
' File size
Dim fileSize
fileSize = load.getFileSize("uploads")
' File size translated
Dim fileSizeTranslated
fileSizeTranslated = load.getFileSizeTranslated("uploads")
' Content Type
Dim contentType
contentType = load.getContentType("uploads")
' No. of Form elements
Dim countElements
countElements = load.Count
' Value of text input field "name"
Dim nameInput
nameInput = load.getValue("txtName")
' Value of text input field "email"
Dim EmailAddress
EmailAddress = load.getValue("txtEmail")
Dim projectDescription
projectDescription = load.getValue("lstDescription")
' destroying load object
Set load = Nothing
' Connection string
Dim connStr
connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="
connStr = connStr & Server.MapPath("db/requestAQuote.mdb")
' Recordset object
Dim rs
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "requestQuote", connStr, 2, 2
' Checking to make sure if file was uploaded
If fileSize > 0 Then
' Adding data
rs.AddNew
rs("Name") = nameInput
rs("EmailAddress") = EmailAddress
rs("DescriptionOfProject") = projectDescription
rs("Upload").AppendChunk fileData
rs("File Name") = fileName
rs("File Size") = fileSize
rs("Content Type") = contentType
rs.Update
rs.Close
Set rs = Nothing
Response.Write "<font color=""green"">File was successfully uploaded..."
Response.Write "</font>"
Else
Response.Write "<font color=""brown"">No File Selected For Uploading"
Response.Write "...</font>"
End If
If Err.number <> 0 Then
Response.Write "<br><font color=""red"">Something went wrong..."
Response.Write "</font>"
End If
%>
or is there any other way for doing the same. any other tutorials?.
i am posting my code here.
This is my html form
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="JavaScript" type="text/javascript">
<!--
function checkform ( form )
{
if (form.txtName.value == "") {
alert( "Please enter your name " );
form.txtName.focus();
return false ;
}
if (form.txtEmail.value == "") {
alert( "Please Enter your Email Address " );
form.txtEmail.focus();
return false ;
}
if (form.lstDescription.value == "") {
alert( "Please Select Project Description " );
form.lstDescription.focus();
return false ;
}
return true ;
}
//-->
</script>
</head>
<body>
<form method="POST" enctype="multipart/form-data" action="insert_request_quote.asp" onsubmit="return checkform(this);">
<table width="472" border="1">
<tr valign="top">
<td width="279" class="style2">Your name <font color="red">*</font><br /></td>
<td width="254"><input class="inputbox" maxlength="50" size="35"
name="txtName" /></td></tr>
<tr valign="top">
<td class="style2">Your email address <font color="red">*</font><br /></td>
<td><input class="inputbox" maxlength="50" size="35"
name="txtEmail" /></td>
</tr>
<tr valign="top">
<td><span class="style2">Please select to best describe this project <font
color="red">*</font><br />
</span><span class="style13"><small>Use the CTRL key to select all that apply</small></span></td>
<td><select multiple="multiple" size="6"
name="lstDescription">
<option value="">-------- Select all that apply ---------</option>
<option
value="Develop a new site">Develop a new site</option>
<option
value="Redesign an existing site">Redesign an existing site</option>
<option
value="Subcontract web design or programming">Subcontract design or programming</option>
<option
value="Make existing site accessible (ADA)">Make existing site accessible (ADA)</option>
<option
value="Make existing site multilingual">Make existing site multilingual</option>
<option value="other (specify below)">Other (specify below)</option>
</select></td>
</tr>
<td class="style2">You can upload a spec document, file or image from your computer</td>
<td><input class="inputbox" type="file" size="30"
name="uploads" /></td>
<tr>
<td height="50" align="middle"> </td>
<td height="50" align="middle">
<div align="left">
<input class="command_button" type="submit" value="Submit" name="submitbt" />
<img
height="8" alt=""
src="Custom quote - the best prices on web site design from India_files/blank.gif"
width="20" border="0" />
<input name="reset" type="reset" class="command_button" value="Reset" />
</div></td></tr>
</table>
</form>
</body>
</html>
THis is my asp code
<% ' insert_request_quote.asp %>
<!--#include file="Loader.asp"-->
<%
Response.Buffer = True
' load object
Dim load
Set load = new Loader
' calling initialize method
load.initialize
' File binary data
Dim fileData
fileData = load.getFileData("uploads")
' File name
Dim fileName
fileName = LCase(load.getFileName("uploads"))
' File path
Dim filePath
filePath = load.getFilePath("uploads")
' File path complete
Dim filePathComplete
filePathComplete = load.getFilePathComplete("uploads")
' File size
Dim fileSize
fileSize = load.getFileSize("uploads")
' File size translated
Dim fileSizeTranslated
fileSizeTranslated = load.getFileSizeTranslated("uploads")
' Content Type
Dim contentType
contentType = load.getContentType("uploads")
' No. of Form elements
Dim countElements
countElements = load.Count
' Value of text input field "name"
Dim nameInput
nameInput = load.getValue("txtName")
' Value of text input field "email"
Dim EmailAddress
EmailAddress = load.getValue("txtEmail")
Dim projectDescription
projectDescription = load.getValue("lstDescription")
' destroying load object
Set load = Nothing
' Connection string
Dim connStr
connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="
connStr = connStr & Server.MapPath("db/requestAQuote.mdb")
' Recordset object
Dim rs
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "requestQuote", connStr, 2, 2
' Checking to make sure if file was uploaded
If fileSize > 0 Then
' Adding data
rs.AddNew
rs("Name") = nameInput
rs("EmailAddress") = EmailAddress
rs("DescriptionOfProject") = projectDescription
rs("Upload").AppendChunk fileData
rs("File Name") = fileName
rs("File Size") = fileSize
rs("Content Type") = contentType
rs.Update
rs.Close
Set rs = Nothing
Response.Write "<font color=""green"">File was successfully uploaded..."
Response.Write "</font>"
Else
Response.Write "<font color=""brown"">No File Selected For Uploading"
Response.Write "...</font>"
End If
If Err.number <> 0 Then
Response.Write "<br><font color=""red"">Something went wrong..."
Response.Write "</font>"
End If
%>