Solved

How to NOT overwrite a value upon update...

Posted on 2004-09-16
28
259 Views
Last Modified: 2008-02-01
I have a back-end user interface.  The user can add a news story and upload picture (via ASPSmartUpload) to his site.  This is how it flows:

Add a Story (uploads images upon click) ----> Confirm the Story (recalls uploaded images for confirmation) ----> Write the record.

The user can then edit that story.  The process is the same.  I call all the record values into form fields for editing.  

Step 1:  Recall the Story and edit it (and upload new images if necessary)  ----> Step 2:  Confirm the changes ----> Step 3:  Update the record

However, my problem is this:  The user may not always upload new images.  When he DOESN'T upload new images in Step 1, the "image" form field in the confirmation form is blank, which passes a blank value back into the database for an update.  Is there any way to basically say, "If no new image is uploaded, always keep the old image path in the database?"  

I know this is confusing.  If you're interested in seeing it in action, let me know and I'll post the link.  It's a test database anyways.
0
Comment
Question by:elevatedmarketing
  • 10
  • 10
  • 8
28 Comments
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 12081603
Before you execute your Update statement, you need to check whether an image is uploaded or not, from there decide whether to update the image path from your database or not..

get what i mean?

regards
0
 
LVL 31

Expert Comment

by:alorentz
ID: 12083206
You need 2 UPDATE Queries:

<%
if request("uploadfile") <> ""
  'run query to update for new file
else
  'run query to only update text
end if
%>

That just the idea, not the right code though....
0
 

Author Comment

by:elevatedmarketing
ID: 12085074
Here's the link to my database interface.  Play around with it and see what you think...

http://www.elevatedmarketing.com/admin/

Only the "Manage News Stories" interface is working now.  Check it out and tell me if you think there's any way to do what my question above is asking.  Thanks for your help.
0
 
LVL 31

Expert Comment

by:alorentz
ID: 12085095
>>Play around with it and see what you think...

No time for that....the answer I provided should work
0
 

Author Comment

by:elevatedmarketing
ID: 12093811
alorentz,

any more specifics on how to do this?  

Adam
0
 
LVL 31

Expert Comment

by:alorentz
ID: 12093901
I guess I don't understand what you don't understand?
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 12093947
Try read the documentation of ASPSmartUpload at:
http://www.aspsmart.com/aspSmartUpload/

And look for the File Object and Count Property there..
http://www.aspsmart.com/aspSmartUpload/liblocal/docs/FileObject.htm#File
http://www.aspsmart.com/aspSmartUpload/liblocal/docs/FilesObject.htm#Count

to check how many files are uploaded and get its relevant info.
0
 

Author Comment

by:elevatedmarketing
ID: 12093968
OK. lemme backup and regroup...

I think I want to handle this this way.  I have an update form for records in a database.  It calls records already in the DB into an html form to edit.  I want to be able to have the choice of uploading new images to the image directory and post the new path to the DB or NOT upload images and keep existing images.  The problem is this: currently, when you don't upload a new image, then it passes a blank value into the database, thereby giving me a little red X when that record is displayed on the viewers end.  What I'd like to do is to use a radio button to give the option of

1) keeping the existing image in the database and thereby pass the unchanged path back into the database OR
2) selecting the radio button and then uploading a new image, thereby allowing the new path to be passed to the database.  

Here's what the HTML form would look like:

<img border="0" src="<%=rsList("Image1")%>"></p>
<input type="radio" value="Current" checked name="CurrentNew">Use Current Image: <input type="text" name="Image1" size="30" value="<%=rsList("Image1")%>" readonly=true onFocus="Blur()">
<input type="radio" name="CurrentNew" value="New">Upload New Image: <input TYPE="file" name="Image1" size="30">

Basically, how do I use a radio button to only pass One of these above values to the next page for processing?

Thanks!
0
 
LVL 31

Expert Comment

by:alorentz
ID: 12093988
You shouldn't use a radio button, you should use a checkbox.  It would say check here to upload new image.  

But if you're going to use radio, you would just check which one is checked:

<%
if request("CurrentNew") = "New" then
   'upload new image
else
   'skip it
end if
%>


Good luck :)
0
 
LVL 31

Expert Comment

by:alorentz
ID: 12093989
>>Basically, how do I use a radio button to only pass One of these above values to the next page for processing?

Because they have the same name, only the value that is selected will be passed!
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 12093997
>>The problem is this: currently, when you don't upload a new image, then it passes a blank value into the database,
Ya.. that means you need to check the radio flag before you doing the updating process..

regarding your code:

>> <input type="text" name="Image1" size="30" value="<%=rsList("Image1")%>" readonly=true onFocus="Blur()">

and

>> <input TYPE="file" name="Image1" size="30">

dont use the same name for them! Personally will prefer to hide the line of:

<input type="text" name="Image1" size="30" value="<%=rsList("Image1")%>" readonly=true onFocus="Blur()">

from user, why? Simply bcos i don't want user to change it.. btw, you can replace it with a hidden field, if you resist..

By reading the value of radio button CurrentNew, we should know whether you want to update the image path file, or keep it as it is.
0
 
LVL 31

Expert Comment

by:alorentz
ID: 12094013
ryancys - I must disagree, they should definitely be named the same, it's the easiest way to get the value.  By naming seperately, you have to use more code to check the value.

Please explain if I misunderstood...
0
 
LVL 31

Expert Comment

by:alorentz
ID: 12094015
Oh, wait, it appears you are naming the text type and file type the same...that is definitely BAD.  I was referring to the radio buttons being named the same (that is GOOD)
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 12094024
>>it appears you are naming the text type and file type the same...that is definitely BAD
Ya, that's what i mean should NOT be same name ;-)
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:elevatedmarketing
ID: 12098371
alorentz:

<<
But if you're going to use radio, you would just check which one is checked:

<%
if request("CurrentNew") = "New" then
   'upload new image
else
   'skip it
end if
%>
>>

Do you have some expanded code for this?  Thanks!
0
 
LVL 31

Expert Comment

by:alorentz
ID: 12098528
No, this forum is not here to write all your code for you, it's to help with problems.  The only way you will learn is to try it yourself!  

Sorry to be so blunt, but to come here and just ask for more and more code isn't favorable.  I have given you the code and the ideas to complete your task.

Good luck!
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 12098620
elevatedmarketing, did you check the documentation link i posted for ASPSmartUpload? I'm sure there Should got some useful examples showing there.. Why don't you try to refer to it?
0
 

Author Comment

by:elevatedmarketing
ID: 12098787
alorentz:

Sorry to have asked for too much.  I have learned a lot here, primarily by being helped by you guys with specific code and then later adapting that code for other uses.  So please accept my humble apologies for requesting too much help.  (For you're information, from some specific code given to me by someone else last week, I've been able to adapt that code to create 6 separate interfaces, so I'm not just asking you to do the job for me!)
0
 

Author Comment

by:elevatedmarketing
ID: 12098818
ryancys,

I did look at the ASPSmartUpload documentation, but it seems to me that it doesn't really help me out here as ASPSmartUpload is working fine.  I could be wrong (and probably am) but it seems to me that my problem lies in my form trying to make it pass either/or value to the DB, somehow by activating or "turning on"  the Upload Capabilities only if needed.
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 12098830
Basically sometimes we're busy of doing our own stuffs, and we can't provide exact solutions for a specified scenario, so then we will try to provide the most correct guidelines as possible as we can, and not providing the exact solution instead.

No bad feeling, and no worries elevatedmarketing  ;-)

>>my problem lies in my form trying to make it pass either/or value to the DB
Are you mean you unable to capturing the data? Try make sure you add:

enctype="multipart/form-data" in your form tag, like:

<form name="form1" enctype="multipart/form-data" method="post" action="process.asp" onsubmit="return validate(this)">

?
0
 

Author Comment

by:elevatedmarketing
ID: 12098922
I can capture the data and I have the enctype set as you say.  this whole interface is working perfectly, except for updating new images.  I can update with new images, and place them into the DB with no problem.  The problem is when you either only upload one new image or don't upload any new images that my image path in my database gets overwritten.  To see it in motion, visit this link, create a full record with 2 images and then only update the record with one image or no images.  You'll see what i mean.

http://www.elevatedmarketing.com/admin/news_list.asp
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 12098941
Can we have a look on your news_reupload.asp as well ?

regards
0
 

Author Comment

by:elevatedmarketing
ID: 12098953
Sorry for the excess code.  Not sure what you're looking for, so I didn't want to cut it out.

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Story Confirmation</title>
<script language="JavaScript" fptype="dynamicanimation">
<!--
function dynAnimation() {}
function clickSwapImg() {}
//-->
</script>
<script language="JavaScript1.2" fptype="dynamicanimation" src="../animate.js">
</script>
</head>

<body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" background="images/background.gif">
<%
'Uncomment ONLY after debugging is complete
'on error resume next

Dim mySmartUpload 'declare the component
Dim intCount ' counter for the number of uploaded files
Dim File 'declare the file to upload
Dim filename 'Temp filename
Dim nextPage 'Next Page to forward to

intCount=0 'initialize the counter

'component creation
Set mySmartUpload= Server.CreateObject("aspSmartUpload.SmartUpload")

'limit the file size to 250 Kb, Larger size not recommended
mySmartUpload.MaxFileSize = 250000

' limit the file extensions to pictures files
mySmartUpload.allowedFilesList="gif,jpg"

'Select files on the user computer
mySmartUpload.Upload
' checking all the files
dim arrImages(2)
For each file in mySmartUpload.Files
 If not File.IsMissing then
     ' Add a session number to the file name
        fileView = file.FileName
      arrImages(intCount) = "http://www.elevatedmarketing.com/admin/uploads/news/" & file.filename
       filename= Server.MapPath(".\") & "\uploads\news\" & file.FileName
      file.SaveAs(filename)
     intCount = intCount + 1
 End If
Next



%>

<div align="center">
      <table border="0" cellpadding="0" cellspacing="0" width="725" id="table1">
            <tr>
                  <td height="100" colspan="2">
                  <!--webbot bot="Include" U-Include="admin_header.htm" TAG="BODY" --></td>
            </tr>
            <tr>
                  <td height="41" colspan="2">
                  <!--webbot bot="Include" U-Include="admin_top.htm" TAG="BODY" --></td>
            </tr>
            <tr>
                  <td width="179" background="images/bg_menu.gif" valign="top">
                  <!--webbot bot="Include" U-Include="admin_menu.htm" TAG="BODY" --></td>
                  <td width="580" background="images/bg_body.gif" valign="top">
                  <table border="0" cellpadding="0" cellspacing="0" width="542" id="table3">
                        <tr>
                              <td width="14">&nbsp;</td>
                              <td>
                              &nbsp;                              <p align="center"><b><font face="Arial"><br>
                              Update Confirmation</font></b>&nbsp;
                              </p>

<form METHOD="POST" ACTION="/admin/news_UpdateRecord.asp">
  <table CELLSPACING="0" CELLPADDING="3" BORDER="1" WIDTH="474">

    <tr>
      <td width="150" align="right" bgcolor="#B3BECA"><b>
            <font face="Verdana" style="font-size: smaller">ID</font><small><font face="Verdana"> :&nbsp;
            </font></small></b></td>
      <td width="324" bgcolor="#DFE3E7"><small><font face="Verdana">
          <input name="ID" value="<%=mySmartUpload.Form("ID")%>" size="4" readonly=true></font></small></td>
         </tr>

    <tr>
      <td width="150" align="right" bgcolor="#B3BECA"><b>
            <font face="Verdana" style="font-size: smaller">Date</font><small><font face="Verdana"> :&nbsp;
            </font></small></b></td>
      <td width="324" bgcolor="#DFE3E7"><small><font face="Verdana">
          <input name="Date" value="<%=mySmartUpload.Form("Date")%>" size="12"></font></small></td>
         </tr>
          <tr>
      <td width="150" align="right" bgcolor="#B3BECA"><b>
            <font face="Verdana" style="font-size: smaller">Location</font><small><font face="Verdana"> :&nbsp;
            </font></small></b></td>
      <td width="324" bgcolor="#DFE3E7"><small><font face="Verdana">
          <input name="Location" value="<%=mySmartUpload.Form("Location")%>" size="40"></font></small></td>
              </tr>
               <tr>
      <td width="150" align="right" bgcolor="#B3BECA"><b>
            <font face="Verdana" style="font-size: smaller">Title</font><small><font face="Verdana"> :&nbsp;
            </font></small></b></td>
      <td width="324" bgcolor="#DFE3E7"><small><font face="Verdana">
          <input name="Title" value="<%=mySmartUpload.Form("Title")%>" size="40"></font></small></td>
                   </tr>
                    <tr>
      <td width="150" align="right" bgcolor="#B3BECA"><b>
            <font face="Verdana" style="font-size: smaller">Author</font><small><font face="Verdana"> :&nbsp;
            </font></small></b></td>
      <td width="324" bgcolor="#DFE3E7"><small><font face="Verdana">
          <input name="Author" value="<%=mySmartUpload.Form("Author")%>" size="40"></font></small></td>
                        </tr>
                         <tr>
      <td width="150" align="right" valign="top" bgcolor="#B3BECA"><b><small>
            <font face="Verdana">Body :&nbsp; </font></small></b></td>
      <td width="324" bgcolor="#DFE3E7"><small><font face="Verdana">
          <textarea name="Body" rows="10" value="" cols="40"><%=mySmartUpload.Form("Body")%>
</textarea></font></small></td>
                             </tr>
    <tr>
      <td align="right" bgcolor="#B3BECA"><b>
            <font face="Verdana" style="font-size: smaller">Image #1</font><small><font face="Verdana">&nbsp;:&nbsp; </font></small>
            </b></td>
      <td bgcolor="#DFE3E7">
          <input type="text" name="Image1" size="30" value="<%=arrImages(0)%>" readonly=true onFocus="Blur()">
            <img src="<%=arrImages(0)%>" width="50" height="50">
            </td>
    </tr>

    <tr>
      <td align="right" bgcolor="#B3BECA"><b><small><font face="Verdana">Image
            #2&nbsp;:&nbsp; </font></small></b></td>
      <td bgcolor="#DFE3E7">
          <input type="text" name="Image2" size="30" value="<%=arrImages(1)%>" readonly=true onFocus="Blur()">
            <img src="<%=arrImages(1)%>" width="50" height="50">
          </td>
    </tr>

    <tr>
      <td width="150" align="right" bgcolor="#B3BECA">
            <b><small><font face="Verdana">Contact :&nbsp; </font></small></b></td>
      <td width="324" bgcolor="#DFE3E7">
            <select name="Contact" size="1">
      <option selected value="<%=mySmartUpload.Form("Contact")%>"><%=mySmartUpload.Form("Contact")%>
      </option>
                <OPTION>Cy Emerus</OPTION>
                  <option>Gary Hummel</option>
                  <option>Charles Jenkin</option>
                  <option>Anthony Fedele</option>
                  <OPTION>Skip Joeckel</OPTION>
          <option>Adam Barrington</option>
      </select>       </td>
    </tr>

                             <tr>
      <td align="right" bgcolor="#B3BECA"><b><small><font face="Verdana">Email :&nbsp;
            </font></small></b></td>
      <td bgcolor="#DFE3E7">
          <select size="1" name="Email">
            <option selected value="<%=mySmartUpload.Form("Email")%>"
            </option>
                      <%=mySmartUpload.Form("Email")%>
                      <OPTION value="travel@cyemerus.com">travel@cyemerus.com</OPTION>
          <option value="gary@cyemerus.com">gary@cyemerus.com</option>
                  <option value="cjenkin@cyemerus.com">cjenkin@cyemerus.com</option>
                  <option value="anthony@cyemerus.com">anthony@cyemerus.com</option>
          <OPTION value="skip@cyemerus.com">skip@cyemerus.com</OPTION>
          <OPTION value="adam@cyemerus.com">adam@cyemerus.com</OPTION>
            </select></td>
                                  </tr>


    <tr>
      <td colspan="2" width="474" bgcolor="#B3BECA"><div align="center"><center><p><small><font face="Verdana">
            <input
      TYPE="submit" value="Update Story!" style="font-family: Verdana; font-size: 12pt; font-weight: bold"> </font></small></td>
    </tr>
  </table>
</form>

<%

' initialize the object
Set mySmartUpload=nothing
%>
</BODY></td>
                              <td width="40">&nbsp;</td>
                        </tr>
                  </table>
                  </td>
            </tr>
            <tr>
                  <td colspan="2">
                  <!--webbot bot="Include" U-Include="footer.htm" TAG="BODY" --></td>
            </tr>
      </table>
</div>

</body>

</html>
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 12098998
No, i would like to see how you construct your Update SQL statement.. For the page you posted above, i prefer to news_UpdateRecord.asp

(sorry, if i mass it out with news_reupload.asp ..)
0
 

Author Comment

by:elevatedmarketing
ID: 12099015
Here you go:

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
<script language="JavaScript" fptype="dynamicanimation">
<!--
function dynAnimation() {}
function clickSwapImg() {}
//-->
</script>
<script language="JavaScript1.2" fptype="dynamicanimation" src="../animate.js">
</script>
</head>

<body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" background="images/background.gif">

<div align="center">
      <table border="0" cellpadding="0" cellspacing="0" width="725" id="table1">
            <tr>
                  <td height="100" colspan="2">
                  <!--webbot bot="Include" U-Include="admin_header.htm" TAG="BODY" --></td>
            </tr>
            <tr>
                  <td height="41" colspan="2">
                  <!--webbot bot="Include" U-Include="admin_top.htm" TAG="BODY" --></td>
            </tr>
            <tr>
                  <td width="179" background="images/bg_menu.gif" valign="top">
                  <!--webbot bot="Include" U-Include="admin_menu.htm" TAG="BODY" --></td>
                  <td width="580" background="images/bg_body.gif" valign="top">
                  <table border="0" cellpadding="0" cellspacing="0" width="542" id="table3">
                        <tr>
                              <td width="14">&nbsp;</td>
                              <td>
                              &nbsp;                              <p align="center"><b>
                              <font face="Arial">Your Story Was Updated Successfully!</font></b></p>
                              <p align="center">&nbsp;</p><font face="Arial">
                              <p align="center">
                              <a href="news_add.asp">
                              <span style="text-decoration: none; font-weight:700">
                              <font color="#400D0C">Add Another Story</font></span></a></p>
                              <p align="center">
                              <a href="news_list.asp">
                              <span style="text-decoration: none; font-weight:700">
                              <font color="#400D0C">Go to News and Press Releases Home</font></span></a></p>
                              <p align="center"><a href="index.asp">
                              <span style="text-decoration: none; font-weight:700"><font color="#400D0C">Go Back to the Main
                              Menu</font></span></a></p></font><font face="Verdana"><b>
<p>&nbsp;<%
dim strDataPath, objConnection
strDataPath = ("C:\Accounts\elevated\data\cyemerus.mdb")
set objConnection=Server.CreateObject("ADODB.Connection")
strConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;"_
       & " Data Source= " & strDataPath & ";"_
       & " Mode=Share Deny None;User Id=admin;PASSWORD=;"

objConnection.ConnectionTimeout = 15
objConnection.CommandTimeout =  10
objConnection.Mode = 3 'adModeReadWrite
if objConnection.state = 0 then
  objConnection.Open strConnectString
end if

dim strSQL, objRS, sID
sID = request("ID") ''you'll have to change this to get the ID however you currently get it using your code

   strSQL = "SELECT * FROM News WHERE ID = " & sID
   

set objRS=Server.CreateObject("ADODB.RecordSet")
objRS.Open strSQL,objConnection,3,3
     objRS("Title") = Request.Form("Title")
     objRS("Image1") = Request.Form("Image1")
     objRS("Image2") = Request.Form("Image2")
     objRS("Email") = Request.Form("Email")
     objRS("Contact") = Request.Form("Contact")
     objRS("Author") = Request.Form("Author")
     objRS("Date") = Request.Form("Date")
     objRS("Body") = Request.Form("Body")
     objRS("Location") = Request.Form("Location")
objRS.Update()
objRS.Close()
Set objRS = Nothing
objConnection.Close()
set objConnection = Nothing

%>
</td>





<%

' initialize the object
Set mySmartUpload=nothing
%>
                              <td width="40">&nbsp;</td>
                        </tr>
                  </table>
                  </td>
            </tr>
            <tr>
                  <td colspan="2">
                  <!--webbot bot="Include" U-Include="footer.htm" TAG="BODY" --></td>
            </tr>
      </table>
</div>

</body>

</html>
0
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 500 total points
ID: 12099041
Try change:

 objRS("Image1") = Request.Form("Image1")
     objRS("Image2") = Request.Form("Image2")

to

if Request.Form("Image1") <> "" then objRS("Image1") = Request.Form("Image1")
if Request.Form("Image2") <> "" then objRS("Image2") = Request.Form("Image2")

working?
0
 

Author Comment

by:elevatedmarketing
ID: 12099098
OK.  That does work partially.  You can change information without uploading new files and NOT overwrite the paths in the DB.  ALSO, you can upload two new files and write new paths to the DB.  Also you can upload a new image for Image 1 and the path is placed in the DB correctly.  The problem is when you just replace image 2, it actually writes that path and places it in the image 1 field in the DB.  I think this is because I've used arrImages(0) and arrImages(1) for those values in the reupload form.

What do you think?

Try it for yourself (don't worry about messing up any values--this is just the test DB anyway)  http://www.elevatedmarketing.com/admin/news_list.asp

Thanks!
Adam
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 12100214
See:
http://www.aspsmart.com/aspSmartUpload/liblocal/docs/FilesObject.htm#Item

You may need to check the uploaded file item's name, and then determine which field in database to update with.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now