QueryString 插入 SQL selectdate= 语句
好吧,我有一个页面,用户输入日期点击按钮,查询字符串被放置在我的其他页面中。我希望他们输入的这个日期被放入我的 sql 语句中。我此时正在使用 javascript 读取查询字符串,但无法将其放入我的 sql 语句中。
<!--
function querySt(ji) {
hu = window.location.search.substring(1);
gy = hu.split("&");
for (i=0;i<gy.length;i++) {
ft = gy[i].split("=");
if (ft[0] == ji) {
return ft[1];
}
}
}
var rundate = querySt("rundate");
document.write(rundate);
document.write("<br>");
-->
我被告知要使用声明和设置语句,但我不断收到错误。任何想法我都被困在这两天了,我相信你们都知道那是什么感觉。
selectdata= "SELECT............ Having dbo.BOOKINGS.BOOKED = CONVERT(INT, DATEADD(dd, DATEDIFF(dd, 0, '11-04-2010'), 0))+2
Alright so I have a page that the user types in a date hits a button and a querystring is placed in my other page. I want this date that they typed to be placed into my sql statement. I am reading the querystring useing javascript at this point, but i cannot get it into my sql statement.
<!--
function querySt(ji) {
hu = window.location.search.substring(1);
gy = hu.split("&");
for (i=0;i<gy.length;i++) {
ft = gy[i].split("=");
if (ft[0] == ji) {
return ft[1];
}
}
}
var rundate = querySt("rundate");
document.write(rundate);
document.write("<br>");
-->
I was told to use a declare and set statement but i kept getting errors.. Any ideas I have been stuck on this for 2 days, im sure you all know how that feels.
selectdata= "SELECT............ Having dbo.BOOKINGS.BOOKED = CONVERT(INT, DATEADD(dd, DATEDIFF(dd, 0, '11-04-2010'), 0))+2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将问题分解为几个部分。现在忽略 sql 内容,只需确保您的函数正确获取字符串并打破“rundate”参数即可。这部分看起来没问题,只要线
窗口.位置.搜索;
实际上得到了一个正确的字符串。
有两个建议可能不适用于您的问题,但却是很好的做法:使用alert()而不是document.write(),并将“var”放在局部变量之前,这样它们就不会污染全局命名空间。即:
等等。
Try breaking the problem down into parts. Ignore the sql stuff for now, just make sure your function is getting the string correctly and breaking out the "rundate" parameter. That part looks ok, as long as the line
window.location.search;
is actually getting a correct string.
Two suggestions that probably don't apply to your problem, but are good practice: use alert() rather than document.write(), and put "var" before local variables so they don't pollute global namespace. That is:
etc.