本人想做一个用户注册网页,用的是Access数据库,请问怎样做代码?需要登陆名,用户名,密码三项内容
<!------------------ 前台登录页面 ------------------->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>登录</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="login.aspx">
<label>登录名
<input type="text" name="loginname" />
</label>
<p>
<label>用户名
<input type="text" name="username" />
</label>
</p>
<p>
<label>密码
<input type="password" name="password" />
</label>
</p>
<p>
<label>
<input type="submit" name="Submit" value="登录" />
</label>
</p>
</form>
</body>
</html>
<!------------------ 前台注册页面 ------------------->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>注册</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="reg.aspx">
<label>登录名
<input type="text" name="loginname" />
</label>
<p>
<label>用户名
<input type="text" name="username" />
</label>
</p>
<p>
<label>密码
<input type="password" name="password" />
</label>
</p>
<p>
<label>
<input type="submit" name="Submit" value="登录" />
</label>
</p>
</form>
</body>
</html>
你先手动开一个数据库user_info,里面三个字段:username,loginname,password
后台页面 c# / .net
-----------------------------login.aspx---------------------------
<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" %>
<%
SqlConnection conn = new SqlConnection("Driver= {MicrosoftAccessDriver(*.mdb)};DBQ=C:\App1\你的数据库名.mdb;Uid=你的用户名;Pwd=你的密码;");
conn.Open();
//应该先过滤用户输入,以免sql注入漏洞
string sql =
"select * from user_info where user='"
+Request.Form["username"]+"' and loginname='"+Request.Form["loginname"]+"' and password='"+Request.Form["password"]+"'";
SqlCommand cmd = new SqlCommand(sql,conn);
SqlDataReader reader = null;
reader = cmd.ExecuteReader();
if (reader.Read()){
//记录存在
Response.Write( reader[0].ToString() );
Response.Write("登录成功");
} else {
Response.Write("用户名不存在或密码错误");
}
reader.Close();
conn.Close();
%>
-----------------------------reg.aspx---------------------------
<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="gb2312" %>
<%
SqlConnection conn = new SqlConnection("Driver= {MicrosoftAccessDriver(*.mdb)};DBQ=C:\App1\你的数据库名.mdb;Uid=你的用户名;Pwd=你的密码;");
conn.Open();
//应该先过滤用户输入,以免sql注入漏洞
string sql0="select * from user_info where username='"+Request.Form["username"]+"'";
//先判断用户名是否存在
SqlCommand cmd0 = new SqlCommand(sql0,conn);
SqlDataReader reader = null;
reader = cmd0.ExcuteReader();
if (reader.Read()){
//记录存在
Response.Write("用户名已存在,注册失败");
} else {
string sql =
"insert into user_info values '"
+Request.Form["username"]+"','"+Request.Form["loginname"]+"','"+Request.Form["password"]+"'";
SqlCommand cmd = new SqlCommand(sql,conn);
cmd.ExecuteNonQuery();
Response.Write("注册成功");
}
reader.Close();
conn.Close();
%>