我在个人blog数据库的blog_content(记录日志的)表里加了一个log_pwd的字段,用来储存日志的密码。
现在在首页里需要判断日志log_pwd字段的值是否为空,若为空就直接进入日志页面,非空则提示要输入密码以后才能进入。
由于日志的ID是自动增加的,应该怎样动态读取数据库里每一篇日志的密码呢?
谢谢了
參考答案:<!--日志列表.asp-->
<%
Set rs= Server.CreateObject("ADODB.Recordset")
rs.open"select * from blog_content",conn,1,1
if rs.eof and rs.bof then
response.write ("没有数据")
else
response.write ("<table>")
for i=1 to 50 '打开数据从1到50循环'
response.write ("<tr><td><a href=日志显示页面.asp?id=")&rs("log_id")&(">")&rs("日志字段名")&("</a></td><tr>") '这句话显示日志的题目链接'
rs.movenext
if rs.eof then exit for
next
response.write ("</table>")
end if
rs.close:set rs=nothing
%>
<!--日志显示页面.asp-->
<%
id=request("id") '这儿的ID是获取上页面的ID号'
if not isnumeric id then id = "" '这儿是判断ID是否数字,如果不是则ID为空'
pwd=request("pwd") '这儿是获取密码'
Set rs= Server.CreateObject("ADODB.Recordset")
rs.open"select * from blog_content where log_id="&id&"",conn,1,1 '这儿是打开log_id与ID相等的数据'
if rs.eof then
response.write ("没有找到相关文章")
else
if pwd = "" or pwd=rs("log_pwd") then
response.write rs("日志字段")
rs.close:set rs=nothing
else
%>
<form action="日志显示页面.asp?id=<%rs("log_id")%>" method="post" name="pwd">
<input name="pwd" type="text">
<input type="submit" name="Submit" value="提交">
</form>
<%
end if
end if
%>
没测试,不知道对不对,如果还有问题请加QQ***********