?
Solved

DW8 Uploading Images Loop to Insert into mdb

Posted on 2007-10-21
11
Medium Priority
?
234 Views
Last Modified: 2010-04-25
Hi
This is actually working fine, but I need to make a change that has me stumped....

I have a form on a an ASP VB page that has three fields for images (A) below.

On the following page I have some uploas (ASP Upload) code as in (B) below.

Now as it is it's fine, but I have now added a further field to the image table which is a boolean - for 'featured image' this willl show true for the FIRST or only (if one) image that is loaded and false for the subsequent images of the three. This is so that in the produduct list pages, the main image shows, and in the detail page for the product there is an option to view the additional images.

I have managed to do this before but was storing the images in the database itsel (not a very good idea, and will be coming back to haunt me/us one day soon :) So my previous code isn't helping.

I guess I need to lose or adapt the loop to add 'Featured' first time round?

Any ideas? Let me know if I should paste up any more of the code, not that there is much.

Thanks a lot

Dave
______________________________________________________________
(A)
<td align="left" class="labelText"><input name="FILE" type="file"  id="FILE" size="40" /></td>
                  </tr>
                  <tr>
                    <td align="left" class="formLabelsSmall">Image 2:</td>
                    <td align="left" class="labelText"><input name="FILE2" type="file" id="FILE2" size="40" /></td>
                  </tr>
                  <tr>
                    <td align="left" class="formLabelsSmall">Image 3: </td>
                    <td align="left" class="labelText"><input name="FILE3" type="file" id="FILE3" size="40" />
________________________________________________________________________________
(B)

      <%  
      Set Upload = Server.CreateObject("Persits.Upload")  
      Upload.Save 'Server.mapPath("../databases/img/prodimages/")
%>  
<h1 align="center"> Image Upload Confirmation:</h1>
<div align="center" class="warning"><br />


<%  
      For Each File in Upload.Files
      
      ' Obtain file name
      Filename = file.Filename

      ' check if file exists in c:\upload under this name
      If Upload.FileExists (Server.mapPath("../../databases/img/" & filename)) Then
      Response.Write "WARNING:<br />Image named - " & File.Path & " - already exists.<br /> Please RENAME this image and load again via the additional images admin menu.<br /><br />"
      Else
      ' otherwise save file
      File.SaveAs Server.mapPath("../../databases/img/" & File.Filename)
      Dim MM_editCmd
      Set MM_editCmd = Server.CreateObject ("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_MagicalRooms_STRING
      MM_editCmd.CommandText = "INSERT INTO tblImages (ProdID, Image) VALUES (?, ?)"
    MM_editCmd.Prepared = true
      MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 5, 1, -1, Upload.Form("frmprodid")) ' adDouble
      MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 202, 1, 255, Filename) ' adVarWChar
   
   
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close
      End If
Next
0
Comment
Question by:swordfishsoup
  • 6
  • 5
11 Comments
 
LVL 25

Expert Comment

by:Rouchie
ID: 20146207
Hi Dave

Sorry it's taken so long to reach you, I've been a bit overwhelmed.  Now, as per usual before I start to help I need a bit more info/clarification!

You want only the first image to be featured, correct?  Therefore, if I upload 2 images, only the first image is classed as featured?
If I only upload 1 image, then that is automatically classed as featured, correct?

Also, what is the name of the feature image boolean column in the database, and is it inside tblImages?
0
 

Author Comment

by:swordfishsoup
ID: 20146269
HI

Good to hear from you again.

First though, my client decided that they wanted to add different prices to different sizes for a product. Once I got over the initial shock and horror.....I realised I could use the same principle that you showed me for the add stock adventure. Counting the rows and then inserting them. So what I thought was going to be a complete nightmare thanks to you was a breeze. Very grateful.

Anyhow. Yes and Yes. First image is always featured. tblIimages contains all the fields (ProdID, Image(***.jpg etc) and Featured which is a checkbox Yes/No

I'm sure I should be able to work this out. Must be an insert 'Featured' followed by 'If Not Nothings' insert not Featured. I guess my confusion is tat I'm adapting an ASP upload page which has for each, so it's harder for me to pick it apart and adapt.

If you're really snowed under maybe you could give me pointers and I'll have a go (You'll still get your lovely points of course :) I might learn more that way too.

Anyhow thanks. I noticed you up the top of the charts on here today so well done for that

Have a good one

Dave
0
 
LVL 25

Accepted Solution

by:
Rouchie earned 2000 total points
ID: 20146365
>> So what I thought was going to be a complete nightmare thanks to you was a breeze.
You're welcome!  It all gets easier with time!

>> I noticed you up the top of the charts on here today
LOL I'd be at number 1 for good if ASP hosting was as cheap as PHP, and more people were using it!  Anyway if Jason reads this I'm sure he'll have something to add...!

Anyway, you can achieve what you need really simply by using a counter variable.  If the counter is at 0 (i.e. the first time it loops) then save as Featured, otherwise do the usual.  Let me show you using your code...

            Dim counter
            counter = 0      ' set counter to 0 *before* we start looping (otherwise it will always return to zero)
            For Each File In Upload.Files
                  ' Obtain file name
                  Filename = file.Filename
                  ' check if file exists in c:\upload under this name
                  If Upload.FileExists(Server.MapPath("../../databases/img/" & filename)) Then
                        Response.Write("WARNING:<br />Image named - " & File.Path & " - already exists.<br /> Please RENAME this image and load again via the additional images admin menu.<br /><br />")
                  Else
                        ' otherwise save file
                        File.SaveAs(Server.MapPath("../../databases/img/" & File.Filename))
                        Dim MM_editCmd
                        MM_editCmd = Server.CreateObject("ADODB.Command")
                        MM_editCmd.ActiveConnection = MM_MagicalRooms_STRING
                        If counter = 0 Then
                              MM_editCmd.CommandText = "INSERT INTO tblImages (ProdID, Image, Featured) VALUES (?, ?, ?)"
                        Else
                              MM_editCmd.CommandText = "INSERT INTO tblImages (ProdID, Image) VALUES (?, ?)"
                        End If
                        MM_editCmd.Prepared = True
                        MM_editCmd.Parameters.Append(MM_editCmd.CreateParameter("param1", 5, 1, -1, Upload.Form("frmprodid"))) ' adDouble
                        MM_editCmd.Parameters.Append(MM_editCmd.CreateParameter("param2", 202, 1, 255, Filename)) ' adVarWChar
                        If counter = 0 Then
                              MM_editCmd.Parameters.Append(MM_editCmd.CreateParameter("param3", adBoolean, adParamInput, True))
                        End If
                        MM_editCmd.Execute()
                        MM_editCmd.ActiveConnection.Close()
                        counter = counter + 1 ' increase counter to stop FEATURED being saved next time
                  End If
            Next

Note that the createParameter command for our Featured item might need amending based on your database software - I've presumed SQL Server but give it a try and let me know.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 25

Expert Comment

by:Rouchie
ID: 20146371
Also if you use the above, make sure that the Default Value in the database for the Featured column is 0 (or False/No).
0
 

Author Comment

by:swordfishsoup
ID: 20146394
Genius. So logical.

It's Access access acually but I'll still give it a go and adpat it where need be.

Will post back result shortly

Thanks a lot Rouchie

Dave
0
 

Author Comment

by:swordfishsoup
ID: 20146575
Hi

Sorry Rouchie.

I've been trawling the net to find how to express the boolean line for mdb
 MM_editCmd.Parameters.Append(MM_editCmd.CreateParameter("param3", adBoolean, adParamInput, True))
but can't find it. I've come up with the number 11.....but don't think that's going to help!!

Do you happen to know what it is please.

Thanks

Dave
0
 
LVL 25

Expert Comment

by:Rouchie
ID: 20146979
You should be able to use either numbers or the actual words to build the command.  Therefore what I wrote should work straight off.   Did you get errors?

Yes 11 does equate to boolean, but if you use the numerical approach you might need to specify a "size" property, and I don't know what that is for boolean values.  It's something like this:

MM_editCmd.Parameters.Append(MM_editCmd.CreateParameter("param3", 11, 1, True))

Tell you what, create a fresh page and get DW to build an insert command for inserting a value into the boolean database table field, then just copy the last bit over what I wrote.  Post it here first though please so I can see for myself, for future reference!
0
 

Author Comment

by:swordfishsoup
ID: 20147027
Yeah I did:
ADODB.Command (0x800A0BB9)
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
/MR07 OffLine/admin/Upload.asp, line 165

I'll do what you suggested and post it back

Thanks
0
 

Author Comment

by:swordfishsoup
ID: 20147058
:) You were right, with the:

MM_editCmd.Parameters.Append(MM_editCmd.CreateParameter("param3", 11, 1, True))

Perfect.

Thanks very much for another great bit of support.

Enjoy the rest of your day

Dave

0
 
LVL 25

Expert Comment

by:Rouchie
ID: 20147095
>> Thanks very much for another great bit of support.

Again, you're welcome!   Keep 'em coming... :-)
0
 

Author Comment

by:swordfishsoup
ID: 20147125
That is not going to be a problem!!

:)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question