【发布时间】:2015-04-04 20:22:20
【问题描述】:
我是 ColdFusion 的新手,想从我的输入字段的值中删除单引号。我试图在谷歌上搜索,我发现使用“magic_quotes_gpc”或“mysql_real_escape_string”,但这些函数在 ColdFusion 中不存在。 ColdFusion中有没有办法处理这种mysql查询注入?
更新:
感谢您的回复,但请看我的代码
<div class="form-group">
<label for="jobDesc">Job description</label>
<textarea name="description" class="form-control" rows="3" id="jobDesc">
<cfif isdefined('userTime')>#userTime.description#</cfif>
</textarea>
</div>
我只想在文本区域中使用单引号,并且我的表单正在提交给事件。查询是:
sqlstr = "";
sqlstr = "insert into usertime set
userid = '#arguments.userTimeParams.userid#',
projectid = '#arguments.userTimeParams.projectid#',
timesheetdate = '#arguments.userTimeParams.timesheetdate#',
estimatedtimespent = '#arguments.userTimeParams.jobhours * 60 + arguments.userTimeParams.jobMins#',
description = '#arguments.userTimeParams.description#',
timeentered = #arguments.userTimeParams.timeentered#;";
queryObj = new query();
queryObj.setDatasource("timesheet");
queryObj.setName("adduserTime");
result = queryObj.execute(sql=sqlstr);
adduserTime = result.getResult();
return result.getPrefix().generatedKey;
我有一个选项可以在字符串中添加斜杠,但是我必须在所有字符串中添加斜杠。那么有没有什么功能或方法可以用更少的代码来做到这一点?
抱歉问了这么多知识有限。
【问题讨论】:
-
使用cfqueryparam 标签(或等效的脚本)。除其他外,它会为您转义引号。
-
仅供参考,您提到的那些功能是 PHP 人员多年前已经修复的巨大设计错误。无论客户端语言如何,您都需要使用准备好的语句。
-
@Alvaro,我已经浏览了很多链接,我知道它们在 php 中已修复,但我在 cf 中找到了任何解决方案,所以我问..无论如何感谢您的宝贵命令
-
关于
wanted to remove single quotes from the values of my input fields,这可能是个坏主意。单引号与撇号具有相同的 ascii 值。这些用于缩写和姓氏。你已经被告知查询参数,通往幸福的道路。
标签: mysql coldfusion