Image Upload and Save Filename to SQL Database
Image Uploads with ADO Recordsets
Hi I'm a new boy to Website Design and Development and need some help with some ASP scripting. My problem briefly is this, I have created a site in which registered uses can insert multipal ads, they can also upload a picture for each ad if they wish. They have the option to upload a picture at the point they create/insert their new ad, or they can add/update their picture at a later point. If they decide to eithr add or update their picture at a lster point, they go to 'Their Ads' page, select the Ad they want to upload a picture for by clicking on a link called 'Upload Image', this takes them to a page with a 'file browse' box and submit button, which is then forwarded to the script page. I have put my script below. My problem is this, i need the script to identify exactly which 'record' needs updating, I assume this is where the 'MM_recordId' plays a part ? but no matter what i try, the script is updating the wrong record, usually the first or last record ! Can you help ? <h1>Test upload & DB update</h1> <form action="test-upload.asp" method="post" enctype="multipart/form-data"><div>Please select file
<input name="MyFile" type="file">
</div>
<input type="submit">
</form>
<% Dim rs
Dim uploadFile
Dim strConnect
Dim MM_recordId
' " UPDATE tbl_Ads SET txtPic1 = (file.filename) WHERE intAds_Id = "MM_recordId"
'strConnect = "SQLOLEDB;Persist Security info="False;Data" source="70.86.220.34;Initial" catalog="myssiSQL;User" id="Tudor;Password=disaster;""
Set rs = Server.CreateObject("ADODB.Recordset")
strConnect = "Driver={SQL Server};Server=????????;Database=myssiSQL;UID=?????;PWD=?????"
rs.Open "tbl_Ads", strConnect, 2, 3
Set uploadFile = Server.CreateObject("Dundas.Upload.2")
On Error Resume Next
uploadFile.Save "c:\WebSites\Tudor\simplysellit.co.uk\Images"
If Err = 0 Then ' Check uploaded files
Response.Write "Uploaded:" & uploadFile.GetFileName(uploadFile.Files(0).Path) & "<br>"
' MM_recordId = 155 ' Search record for update
if Err <> 0 Then
Response.Write "<p>Error saving the file: " & Err.Description
Else
' Ive tried both of these without success
' rs("intAds_Id").Value = & MM_recordId
' rs.Find "intAds_Id=" & MM_recordId
rs("txtPic1").Value = uploadFile.GetFileName(uploadFile.Files(0).Path)
rs.Update Response.Write "<p>Success!<br>"
End If
End If
rs.Close
%>
Comments
Your solution
Drop me an email and send over a script I have created... works well and hasnt given me any trouble.
On further note you could always purchase ASP Upload and it easily solve your problem... But never the less if you want the script just pop me an email.
Regs
Al
You must me logged in to write a comment.