javascript - ColdFusion and AJAX - Updating Database -
javascript - ColdFusion and AJAX - Updating Database -
i'm wanting have scheme set users can go page there's list of items can rate (say, 1 through 5) drop-down. list going quite long much more convenient if go through , rank each item without ever having nail "save."
i'm very much novice when comes ajax figure can't that difficult. found an reply in different discussion think quite relevant doesn't provide plenty info me know it.
in short, how utilize ajax, in congruence jquery , coldfusion, update database without need save/submit button?
clarification: should have clarified user can rate items - not rank. meaning there's no #1, #2, #3, etc. instead, each item can rated on scale 1-5.
currently i'm basing off of ".change()" when user makes selection in drop-down. @ point have 2 jquery variables set "id" of item changed new "rating." need find way utilize these 2 variables update table in database.
updateon main page, have simple jquery ajax post call: $.post('update.cfc', {id: inputid, rating: selrat})
triggered .onchange()
. "inputid" id of entry want update in database , "selrat" selected rating in drop-down.
<cfcomponent output="false"> <cffunction name="updaterating" access="remote" output="false"> <cfupdate datasource="#session.db#" name="update"> update ajaxtest set rating = #form.rating# id = #form.id# </cfupdate> </cffunction> </cfcomponent>
i'm getting 500 (internal server error)
.
thoughts/suggestions?
have tried submitting traditional way form see happens? can add together simple debugging writing file log executed attempt?
one thing stands out me: should <cfupdate
opening , closing tag <cfquery
don't utilize cfupdate or cfinsert, don't think cf flavor supports syntax you're trying use, leads me believe it's easy mistake.
on note, query dangerous, , sorry go off on tangent..
if submitted "0; drop table users" value of id, users table disappears (if have users table). pass other mutual table names members, news, pages, content, cms, transactions. (i wouldn't this, never know when user might.)
there's easy solution, <cfqueryparam>
. i'll allow research tag, i'll show how alter particular query.
<cfquery datasource="#session.db#" name="update"> update ajaxtest set rating = <cfqueryparam cfsqltype="cf_sql_integer" value="#form.rating#"> id = <cfqueryparam cfsqltype="cf_sql_integer" value="#form.id#"> </cfquery>
cfqueryparaming variables stops risk of , passes variable values text rather sql.
javascript jquery ajax coldfusion
Comments
Post a Comment