判断用户的选择问题?????

coffeegirl 2002-07-23 06:32:18
strSql="INSERT INTO fktable(ifopition,productsort,othersort,fkcontent,authorname,email,tel,fax)" _
& " VALUES(" & ifopition & ",'" & productsort & "','" & othersort & "','" & fkcontent & "','" & authorname & "','" & email & "','" & tel & "','" & fax & "')"

值是从表单中取得的,其中有几个值是可以为空的,用户可以填也可以不填,
现在问题是:
怎样判断用户有没有填这个值,填了的值就增添到数据库的相关字段中,没有填的值数据库的相关字段就为空值,用什么方法实现????
怎样改写这个sql语句?????
...全文
48 点赞 收藏 3
写回复
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
eldertiger 2002-07-23
我喜欢这样做,虽然可能比较土:
user_email=request("user_email")
user_pwd=makepassword

str1="user_name,user_pwd,user_email"
str2="'"&user_name&"','"&user_pwd&"','"&user_email&"'"

user_true_name=request("user_true_name")
if user_true_name<>"" then
str1=str1&",user_true_name"
str2=str2&",'"&user_true_name&"'"
end if

user_code=request("user_code")
if user_code<>"" then
str1=str1&",user_code"
str2=str2&","&user_code
end if

sql="insert into table_name ("&str1&") values ("&str2&")"
回复
meizz 2002-07-23
唉,这样更精简些:
strSql="INSERT INTO fktable"& _
"(ifopition,productsort,othersort,fkcontent,authorname,email,tel,fax)VALUES("& _
Trim(Request.Form("ifopition"))&",'"& _
Trim(Request.Form("productsort"))&"','"& _
Trim(Request.Form("othersort"))&"','"& _
Trim(Request.Form("fkcontent"))&"','"& _
Trim(Request.Form("authorname"))&"','"& _
Trim(Request.Form("email"))&"','"& _
Trim(Request.Form("tel"))&"','"& _
Trim(Request.Form("fax"))&"')"
回复
meizz 2002-07-23
dim ifopition,productsort,othersort,fkcontent,authorname,email,tel,fax

ifopition = ""
productsort = ""
othersort = ""
fkcontent = ""
authorname = ""
email = ""
tel = ""
fax = ""

ifopition = Trim(Request.Form("ifopition"))
productsort = Trim(Request.Form("productsort"))
othersort = Trim(Request.Form("othersort"))
fkcontent = Trim(Request.Form("fkcontent"))
authorname = Trim(Request.Form("authorname"))
email = Trim(Request.Form("email"))
tel = Trim(Request.Form("tel"))
fax = Trim(Request.Form("fax"))

strSql="INSERT INTO fktable(ifopition,productsort,othersort,fkcontent,authorname,email,tel,fax)VALUES("&ifopition&",'"&productsort&"','"&othersort&"','"&fkcontent&"','"&authorname&"','"&email&"','"&tel&"','"&fax&"')"

这样每个值都有一个空的初始值了。
回复
发动态
发帖子
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
社区公告
暂无公告