Thank you, its working....
It works with the sample string, yes. But it wouldn't work if the leading characters are something other than "00" which is possible w/UTF16
Thank you, its working....
It works with the sample string, yes. But it wouldn't work if the leading characters are something other than "00" which is possible w/UTF16
Also while it's a bad idea to send passwords in the url, method "post" isn't any more secure than "get".
Since you can't share cookies across domains, maybe both ends could establish a short term "token" for authenticated users. Then you'd pass the token in the cflocation url. The other side checks the token and destroys it. If the token is valid it logs the user in (or whatever it's supposed to do).
Unfortunately I don't know how to decode UTF16. If it were a regular UTF8 string - or the values always had 2 leading zeroes - you could decode it like any 2 char hex string. Loop and grab every 4 characters. Use inputBaseN to get the ascii code, and convert it to a character. Problem is that would not work if the first 2 chars were something other than 00. Not much help I know, but it may give you some ideas.
<cfloop from="1" to="#len(theString)#" index="x" step="4">
<cfset fourChars = mid(theString, x, 4)>
<cfset theChar = chr( inputBaseN( fourChars, 16))>
<cfoutput> character at [#x#] = #theChar# </cfoutput>
</cfloop>
We need to see the INSERT code to hazard a guess.
That's not possible w/cfhttp. Think of cfhttp like a mini browser. The post, and any redirection on the remote server's end, all takes place inside cfhttp. Once the call exits, the user browser is still on your server. The only way to redirect them to another url programmatically is w/cflocation (or a javascript/html form submit).
However, I am not redirected to the URL indicated, I am stuck at the page with the script running my validations.
But it's not clear from the description what part you're stuck on. You cfhttp post data to "some other server". Then what? ie What're you trying to do that's not working?
cfselect name="modelYears"
bind="cfc:data.getModels({modelYear})" >
The bind parameter doesn't match the name of your form field. It should be plural ie modelYears
Binding is harder to debug than a regular query. Take it in steps. Always run cfc code manually first. If the cfc doesn't work by itself, it wont' work in a bind either. The problem will just be harder to find ;-)
http://www.yoursite.com/data.cfc?method=getModels&modelYears=2012
Once it's working enable ajax debugging in the cf admin to see the data being sent back and forth
That won't work. <cflocation> only works with relative paths
cflocation can redirect to an absolute url ie http://www.somesite.com, so I don't think that's the problem.
Double the pound signs. ie Use ## instead of #
examples:
<cfset value = "print ## sign">
<cfoutput>print ## symbol</cfoutput>
its not even a variable with time in it.
...
<cfset ET = timeformat(EndTime, 'H')>
Then why are you using timeFormat on it? :) If EndTime is null, its probably returning an empty string, hence the error when you try and perform subtraction. Make sure it's a number and problem solved.
<cfset ET = "">
<cfset thisFails = ET - 1>
Yeah, I was going to say it would definitely require multiple scripts. But it sounds like you got it figured out.
I haven't done anything like this. So I can't say whether there's a better option. But it certainly sounds doable from a technical standpoint. It's just a series of cfhttp posts and db queries on your end.
What issues are you seeing?
If I'm reading it correctly, you could simplify it using BETWEEN. I left out the cfqueryparam's for brevity.
WHERE who = 20
AND (
( datestart <= #FORM.StartDate# AND
datediscontinued BETWEEN #FORM.StartDate# AND #FORM.EndDate#
)
OR
datestart BETWEEN #FORM.StartDate# AND #FORM.EndDate#
) )
.. and I'm not so sure you even need the datestart <= #FORM.StartDate# check. There should probably be a constraint preventing the discontinue date from being earlier than the start date.
Yeah I think it'd be easier if the table had a date range (effective start to end). I have a meeting now so I'll have to check back later.
1) where date discontinued is between the start and end date
2) If the start date is NEQ to the end date I need to find if there is another entry with a discontinued date
3) if not then output the entries that have a NULL endate.
The 1st one's clear ... but I don't follow the rest of it. Why display records that don't match the filtered dates?
Can you give an example of all 3 cases using your sample data?
> cfc:car3.getModels( {modelYear} )
> WHERE modelID = '#ARGUMENTS.modelID#'
It's because the getModel query doesn't make any sense ;) You're passing in a "year" number, but the query is treating it as a modelID. If you want the models for a specific manufacturer AND year, you need to pass in both values. Then filter on the right columns.
My problem is when I try to select a Year, the models dont change based on that selection
If that's the desired result, your binds are backward. Year is bound to model. So when the year list changes when a model is selected, not the other way around.
Define "not working". What's it doing vs what you want it to do.
What db type?
The fact that this is something not under my control, and puts me at the mercy of my web host, is leading me to put together a case to take to my CF administrator to set up a datasource for me to use.
Establishing a proper CF datasource is the way to go for lots of reasons. The way you're doing it now works, but it's non-standard for the language. So it's like swimming upstream. Remember what may be the normal connection method for php isn't the best method for CF. They're different languages. With your current approach you lose out on most of CF's benefits, like the performance boost of CF's connection pooling. Not to mention exposing your db to risky sql.
With hosted sites, you're always at the mercy of the host. If they change or remove files needed by your web application nothing's going to work. Php's no different. Remove the files it needs to connect and it won't work either. You'd far be less likely to encounter problems if you were using the standard connection method ie CF dsn, because that's something the host administers. They'd have a vested interest in maintaining it because the same settings are used on all of their cf sites. So breaking one would break them all and cause tech support headaches.
Hard to say. There's many causes for that error (do a search on that error without the server name).
-What do the log files say?
-Did you fix the code to always close the connections, because failing to do would cause problems?
-Does the error happen very time, or only sometimes or with certain statements?
The post you have basically show how to create a new data source
No, it doesn't create a datasource, only a connection. It's not the way queries are normally handled in CF either. Normally dsn's are created through the CF Admin and queries are simpler. This way is much more complex and error prone. So don't use it unless you have to.
If you already have CF dsn's, you can use the Admin API to change settings programatically
http://www.mindfiresolutions.com/AccessModify-ColdFusion-Administrator-settings-programmatically-by-ColdFusion-Administrator-API-calls-172.php
Rather than creating an object using resultSet, it was just passing the default name from the argument declaration at the beginning of the function.
That doesn't sound right. I'd have to test it to see what actually, happens. But either way, you shouldn't use that code. Functions aren't like custom tags. They're like a black box. They shouldn't know or care what happens to the results once they've done their job.
I now have:
You're still exiting too soon. "return" means abort the function and don't run any more code. So all that stuff you have after the "return" line never executes .. so you never close the objects.
It looks like you are simply cutting out the middleman ('q'), so to speak, and just returning CreateObject(). This seems to work the same, but your code is cleaner.
Yeah, that's a personal preference thing. They both do the same thing.
Now, when you say I should VAR scope all of the variables, do you mean in the CFScript declarations, like so?
More like the 1st example. But if you don't know what var scoping is, do a search on it. There's lots of examples, and it's an important concept to understand.
http://www.iknowkungfoo.com/blog/index.cfm/2007/8/22/Object-Oriented-Coldfusion--4--The-var-scope
"#query_name#" = CreateObject("java", "coldfusion.sql.QueryTable").init(resultSet);
return "#query_name#";
resultSet.close();
st.close();
con.close();
Couple problems.
1) Your return is in the wrong place. So the function exits before the connections are closed which'll cause big problems.
2) The function shouldn't know, or even care, what variable name the calling page uses. It's only job is to create a query and return it. Period. The correct order is:
resultSet.close();
st.close();
con.close();
return CreateObject("java", "coldfusion.sql.QueryTable").init(resultSet);
3) If your function's in a shared scope, even VARIABLES, you're going to hit all sorts of wonky problems if you don't VAR scope all those variables.
If you're serious, I'd choose CFWACK. They're by far the best CF book IMO. It's what I used to learn CF, combined with the examples in the online documentation.
I recommend most people take a separate course on databases. Because sql is a totally separate beast. Languages like CF, .NET, .PHP, etc... just provide the means to execute sql. You need have a basic understanding of the s-q-l language to do anything with those tools..
But at least the query works
Be sure to scrub the sql string/params. Because you're vulnerable to sql injection without cfqueryparam.
Sounds like troll bait.
I'm just glad it was the 31st. Often examples are ambiguous like 06/10 .. so you don't even know there's a problem until the query blows up. lol
31/8/2011
Also you can't use dd/mm/yyyy format. The standard functions expect values to be in U.S. date format ie mm/dd/yyyy. If your CF server is running under a locale where the standard is dd/mm/yyyy (like in England) then use the LS functions to parse the value first.
http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_p-q_18.html
<cfqueryparam value="#LSParseDateTime("31/8/2011")#" ....>
If your locale IS English/US, then you'll have to split it into month, day and year manually. Then use createDate() to construct the date.
<cfqueryparam value="#createDate(year, month, day)#" ....>
Ok. Sorry it's been so hectic I haven't had a chance yet.
Could store the value in a hidden form field or non-visible html element (read about the "display" attribute). All depends on why you need to do this ..
http://www.w3schools.com/cssref/pr_class_display.asp
What's your CF version?
I tinkered with that a bit, with no luck before trying a few others I found from searching for DSN-less connections.
Sorry I didn't test it. Just assumed it worked. So much for assumptions.. lol Still it was a bad example anyway. So no loss there.
if ( left(trim("query statements"), 6 ) is 'select'){//select statements
That function's better, but not very robust. If I get a chance, I'll try and find one and post it.
However, it did not seem to update my database, which is a different matter for me to investigate.
Run the same statement, credentials,etc... in your php example. If it works there it's a problem with the cffunction.
The info being passed is being generated after the payment info is saved. So I'm not too worried about that.
Just be sure it's not info that can be used to access the payment info either. Because that's just as insecure ;-)
Let me know if you have problems w/the link. If use CF's pure jdbc driver instead of the one in the link. I didn't have time to hunt down a better example. But if you search a little, I know they're some better ones out there.
This information is passed whenever someone registers and pays for a class on there.
Don't they provide other transfer methods, like a web service? Seems strange an outside company would even want you connecting directly to their servers.
Is there a similar way that I can get around using a datasource defined at the admin level, and just directly call the db, as the above script does?
It's possible to create direct jdbc connections, instead of using cfquery. The link below should work .. but it's not a good example. It uses the slow jdbc:odbc driver. Do a search on dsn-less connections for better examples
http://www.hosting.com/support/mysql/coldfusionstring
But I'd be concerned about security. I doubt that method's secure and sending payment info insecurely is a recipe for disaster.
The one on server A needs to pass some info to the one on server B.
How much information? How often?
What are you pointing to that location? Connecting to a remote database MAY be possible if both your firewalls and permissions allow. They often don't for obvious security reasons. What's your setup?
Can't help you with jquery. But why not just use CF's built in autosuggest? Are you running CF8 or higher?
Cool. I like the 1st one (server side), but it's good to have choices ;-)
Sadly it's strictly DIY unless you're running CF9
http://www.dansshorts.com/post/cfselect-binding-and-selectedvalues
http://stevenksavage.com/index.php/archives/14
Print an order where? If you mean server side printing, take a look at <cfprint>. If you mean client side, web pages can't access a user's printer directly for security reasons. The best you can do is display a prompt as shown in the prev link.
<cfif not isdefined("Form.frmpricerange")>
<cfset Form.frmpricerange = "N">
</cfif>
Use <cfparam> instead. It does the same thing in a lot less code.
<cfparam name="Form.frmpricerange" default="N">
It shows no message just says page not found
If you're using IE, it's probably a badly worded error message. Turn off it's friendly error messages or you won't be able to view the real error
http://malektips.com/internet-explorer-8-disable-friendly-error-messages.html
but when I remove the between clause it seems to work
That's because your code isn't generating a valid SQL statement. You're not doing anything when Form.pricerange# is NOT equal to 5000. So your sql is incomplete:
AND ((People.Price) Between {there should be something here})
WHERE (((Check.Date)>=#9/6/2011# And (Check.Date)<>#8/31/2011#)
But overall the query doesn't make sense. There's a lot of contradictory and redundant conditions. Let's step back and figure out what you're trying to do in plain english 1st. Then we can help you put it into SQL.
A few small tips:
- Don't use Access specific syntax for dates ie #9/6/2011# . It's not portable. Better to use cfqueryparam or CreateODBCDate instead.
- A HAVING clause is only needed for aggregates. You're not using any. So all of those conditions belong in the WHERE clause instead
Is there a way, where i can get two values from a option tag
No. If there isn't a unique key you can use instead, you could concatenate the values into a single string. Pick a delimiter that doesn't occur in the data. Then use list functions to separate the values.
<!--- form --->
<option value="#value1#:#value2#">#value2#</option>
<!--- action page --->
<cfset value1 = getToken(form.selvalues, 1, ":")>
<cfset value2 = getToken(form.selvalues, 2, ":")>
Where col1="#value1#" and col2="#value2#"
Don't forget to use cfqueryparam to protect against sql injection.
So how can i know which button was clicked.
Only the button clicked will exist on the action page. If all 4 buttons share the same name, use the button value ie #form.submitButton#
ie
<cfparam name="form.submitButton" default="">
<!--- display selection --->
<cfdump var="#form#">
<form method="post">
<input type="submit" name="submitButton" value="add" />
<input type="submit" name="submitButton" value="divide" />
<input type="submit" name="submitButton" value="multiply" />
<input type="submit" name="submitButton" value="divide" />
</form>
I got strange result from the command.
What do you mean by "strange"? What was the actual error message?
web application. I used MS Access as back-end database.
Honestly MS SQL would be a better choice. MS Access was designed for individuals to use on their desktops, not for web applications.
I just ran a second query looking for dayreturned IS NULL and kept the dayleft where statement
Yep, that'll do it! Good job.
If you want everything in 1 query. Just do somethin like this.
WHERE ID = 193
AND dayLeft < <cfqueryparam value="#dayAfter#" cfsqltype="cf_sql_date">
AND ( <!--- using greater than or equals to also include selectedDate at midnight exactly --->
dayReturn >= <cfqueryparam value="#selectedDate#" cfsqltype="cf_sql_date">
OR dayReturn IS NULL
)
<cfif #dateAdd("d", -1, checkResident.dayleft)
That only checks whatever dates happen to be in the 1st record of the query. Remember you removed the WHERE clause. So there might be more than 1 record returned. For accurate results you'd have to cfloop through the query to check all of them.
The original sql didn't work because I didn't know the data contained times too. So it was the wrong the comparison. Just adjust it to account for the time.
Example: if today is 8/30/2011, #selectedDate# will be 8/10/2011 and #dayAfter# will be 8/11/2011.
<cfset todaysDate = createODBCDate(NOW())>
<cfset selectedDate = dateAdd("d", -20, todaysDate)>
<cfset dayAfter = dateAdd("d", 1, selectedDate)>
<cfquery name="checkResident" datasource="residents5">
SELECT *
FROM hospital
<!--- be sure to use cfqueryparam if resident id is a variable --->
WHERE ID = 193
AND dayLeft < <cfqueryparam value="#dayAfter#" cfsqltype="cf_sql_date">
AND dayReturn > <cfqueryparam value="#selectedDate#" cfsqltype="cf_sql_date">
</cfquery>
Oh, no. Don't use that code. If it works, it's pure luck ;-)
What's this "dayout" and "dayin" value? Are you using those columns or just DAYreturned and DAYleft?
Oops... our responses keep overlapping. lol
We are storing date/times but not using the times for this report. This is a MYSQL DB
Yep. That explains it :) What #selectedDate# did you actually use in your test? Still "07/11/2011"?
Since it's not trivial stuff, I'd rather recommend the right code. But without the debugging output, I don't know if what you posted is right or not ;-) If you can post it, I can tell you what went wrong and how to fix it. Correctly.