?
Solved

if-else statement for coldfusion

Posted on 2009-03-31
6
Medium Priority
?
333 Views
Last Modified: 2013-12-16
I'm a newbie on coldfusion so please someone help me.
<CFset today = NOW()>
 
<cfif not isDefined("Form.fileupload") OR Form.fileupload EQ "">
<cfquery datasource = "technology">
INSERT INTO sharex_2007
VALUES('#Form.title#', #CreateODBCDateTime (Form.date#, '#Form.presenter#', '#Form.group#', '#Form.remarks#', '#Form.ClientFile#', #Form.audience#)
 
</cfquery>
 
<cfelseif>
<cffile action="upload"
filefield="fileupload"
destination="d:\intranet_info\sharing\shared_x\newsharex\2007\"
nameconflict="overwrite">
 
<cfquery datasource = "technology">
INSERT INTO sharex_2007
VALUES('#Form.title#', #CreateODBCDateTime (Form.date#, '#Form.presenter#', '#Form.group#', '#Form.remarks#', '#Form.ClientFile#', #Form.audience#)
 
</cfquery>
 
<cfelseif>
<cffile action="upload"
filefield="fileupload"
destination="d:\intranet_info\sharing\shared_x\newsharex\2007\"
nameconflict="overwrite">
 
<cfquery datasource = "technology">
INSERT INTO sharex_2007
VALUES('#Form.title#', #CreateODBCDateTime (Form.date#, '#Form.presenter#', '#Form.group#', '#Form.remarks#', '#Form.ClientFile#', #Form.audience#)
 
</cfquery>
 
</cfif>

Open in new window

0
Comment
Question by:alexanderax
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 18

Expert Comment

by:Plucka
ID: 24036610
You cant do <cfelseif without another condition should look something like this

<cfif value eq 1>
  do something
<cfelseif value eq 2>
  do something different
<cfelseif value eq 3>
  do something different again>
<cfelse>
   otherwise do this
</cfif>
0
 

Author Comment

by:alexanderax
ID: 24036914
But is there any other ways to use the above statement? I want it to be like when user upload the file into the database, it will automatic updated in the database and it's particular folder(example like 2007 folder, 2008 folder etc..)when uploading excel or pdf file into each of the folder. Below is a must include ccondition after those statement in bold and underlined.



INSERT INTO sharex_2007
VALUES('#Form.title#', #CreateODBCDateTime (Form.date#, '#Form.presenter#', '#Form.group#', '#Form.remarks#', '#Form.ClientFile#', #Form.audience#)





(FIRST condition)
filefield="fileupload"
destination="d:\intranet_info\sharing\shared_x\newsharex\2007\"
nameconflict="overwrite">


INSERT INTO sharex_2007
VALUES('#Form.title#', #CreateODBCDateTime (Form.date#, '#Form.presenter#', '#Form.group#', '#Form.remarks#', '#Form.ClientFile#', #Form.audience#)

(second condition)
filefield="fileupload"
destination="d:\intranet_info\sharing\shared_x\newsharex\2008\"
nameconflict="overwrite">


INSERT INTO sharex_2007
VALUES('#Form.title#', #CreateODBCDateTime (Form.date#, '#Form.presenter#', '#Form.group#', '#Form.remarks#', '#Form.ClientFile#', #Form.audience#)



0
 

Author Comment

by:alexanderax
ID: 24036984
But is there any other ways to use the above statement? I want it to be like when user upload the file into the database, it will automatic updated in the database and it's particular folder(example like 2007 folder, 2008 folder etc..)when uploading excel or pdf file into each of the folder. Below is a must include ccondition after those statement in bold and underlined.

just now did not underline the top few sentence..

<cfif not isDefined("Form.fileupload") OR Form.fileupload EQ "">
<cfquery datasource = "technology">
INSERT INTO sharex_2007
VALUES('#Form.title#', #CreateODBCDateTime (Form.date#, '#Form.presenter#', '#Form.group#', '#Form.remarks#', '#Form.ClientFile#', #Form.audience#)

</cfquery>



(FIRST condition)
<CFFILE
filefield="fileupload"
destination="d:\intranet_info\sharing\shared_x\newsharex\2007\"
nameconflict="overwrite">

<CFQUERY datasource="technology">
INSERT INTO sharex_2007
VALUES('#Form.title#', #CreateODBCDateTime (Form.date#, '#Form.presenter#', '#Form.group#', '#Form.remarks#', '#Form.ClientFile#', #Form.audience#)
</CFQUERY>
(second condition)
<CFFILE
filefield="fileupload"
destination="d:\intranet_info\sharing\shared_x\newsharex\2008\"
nameconflict="overwrite">

<CFQUERY datasource="technology">
INSERT INTO sharex_2007
VALUES('#Form.title#', #CreateODBCDateTime (Form.date#, '#Form.presenter#', '#Form.group#', '#Form.remarks#', '#Form.ClientFile#', #Form.audience#)

</CFQUERY
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 36

Accepted Solution

by:
SidFishes earned 2000 total points
ID: 24041187
couple of things first

avoid calling fields date as this is a reserved word in most db's... use something like theDate  

you're missing a closing )

#CreateODBCDateTime (Form.date)#,

you don't need an if then at all...just get the year

<cfset formYear = datepart("Yyyy",form.theDate)>

and use the variable

<CFFILE
filefield="fileupload"
destination="d:\intranet_info\sharing\shared_x\newsharex\#formYear#\"
nameconflict="overwrite">



<CFQUERY datasource="technology">
INSERT INTO sharex_2007
VALUES(
<cfqueryparam cfsqltype="cf_sql_varchar" value="#Form.title#">,
 <cfqueryparam cfsqltype="cf_sql_date" value="#Form.date#">,
 <cfqueryparam cfsqltype="cf_sql_varchar" value="#Form.presenter#">,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#Form.group#">,
<cfqueryparam cfsqltype="cf_sql_longvarchar" value="#Form.remarks#">,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#Form.ClientFile#">,
<cfqueryparam cfsqltype="cf_sql_integer" value=" #Form.audience#">)
</CFQUERY>

I've used <cfqueryparam..> because if you don't you -will- be hacked via sql injection if this is a publically accessible
website. Even if not, it's a good idea to use it. You can eliminate the createodbcdate as cfqueryparam handles the binding itself

0
 

Author Closing Comment

by:alexanderax
ID: 31565201
thanks SidFishes for the solution. now i still got another problems. i now trying to develop an web-base search engine. i'm not sure why i when i input numbers in the text box, there's no results shown or that particular file was not shown.  
0
 

Author Comment

by:alexanderax
ID: 24155633
Hi SidFishes, recently i found out that when i uploaded my files, it can be successfully uploaded BUT when i click new upload for new author again, the folder that the files should be saving inside, "overwrite" my current file that's been uploaded previously and same goes to updating. Example: Like when i UPLOAD "rash.xsl",  it WILL save the excel file to the 2008 folder but when i go to my edit page and click browse to upload the "rash.xsl" file again (assuming that i already updated the rash.xsl), and i click on the "UPDATE" button, the 2008 folder suppose to have this "rash.xsl" with the updated version but instead the files DISAPPEAR!!  But if i browse and upload another files like "new.xsl", that particular files will still be saved to the 2008 folder together with the old VERSION rash.xsl files. All i know is that same filename will disappear but diffenert won't. Want i want is to be able to update older excel/word/pdf etc files instead of keep deleting the old one then upload the new one up.  May i know why is this happening?
0

Featured Post

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…
Suggested Courses

800 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