<%@ page contentType="text/html;charset=gb2312"%>
<%@ page language="java"import="java.sql.*"%>
<jsp:useBean id="userBean"scope="page"class="regist.conn"/>
<%!
  public String getStr(String str)
  {
    try
     {
        String temp_p=str;
        byte[]temp_t=temp_p.getBytes("ISO8859-1");
        String temp=new String(temp_t);
        return temp;
     }
  catch(Exception e){}
  return "null";
  }
%>
<%!
  String logname,realname,passwd1,passwd2,email,gender;
String phone,address;
boolean regAttempt=false;
String errorMessage="";
%>
<%//out.println("request.getParameterValues("logname")");
//必须填写的项目
 logname=request.getParameter("logname");
 realname=request.getParameter("realname");
 passwd1=request.getParameter("passwd1");
 passwd2=request.getParameter("passwd2");
 email=request.getParameter("email");
 gender=request.getParameter("gender");
//非必须填写的项目
 phone=request.getParameter("phone");
 if(phone.trim().equals("")){phone=null;}
 address=request.getParameter("address");
 if(address.trim().equals("")){address=null;}
///转换中文
logname=getStr(logname);
realname=getStr(realname);
passwd1=getStr(passwd1);
email=getStr(email);
gender=getStr(gender);
phone=getStr(phone);
address=getStr(address);
%>
<%
 String sql="select ID from registmessage where  logname='"+logname+"'";
 ResultSet RS=userBean.executeQuery(sql);
  int rowscount=0;
 try
  {
    while(RS.next()){rowscount++;}
  }
 catch(Exception e){}
//out.println(rowscount);
 if(rowscount==0)
 {
   regAttempt=true;
   String sqlinsert="insert into registmessage(logname,password,realname,gender,email,phone,address) Values('"+logname+"','"+passwd1+"','"+realname+"','"+gender+"','"+email+"','"+phone+"','"+address+"')";
  userBean.executeQuery(sqlinsert);
 session.setAttribute("username",logname);
 response.sendRedirect("reg_sus.jsp");
 }
 else 
 {
   errorMessage="对不起，这个用户名已经存在！";
   session.setAttribute("username","");
 }
%>
<html>
<head>
<title>reg</title>
</head>
<body >
<table border="0"width="100%"cellspacing="0"cellpadding="0"height="307">
<tr align="center">
<td width="100%"colspan="4"height="20"bgcolor="#3399ff">&nbsp;
<font color="#ffffff">新成员注册新成员注册新成员注册</font>
</td>
</tr>
<tr>
<td align="center"height="32"width="40%">
<font color=red><%=errorMessage%></font>
</td>
<tr>
<td width="100%"align="center"colspan="4"height="36">粗体内容必须填写</td>
</tr>

<form name="form1" method="post" action="reg_ok.jsp">

<tr>
<td align="right"><b>真实姓名:</b></td>
<td>&nbsp;</td>
<td colspan="2">
<input type="text" name="realname"value="">
</td>
</tr>

<tr>
<td align="right"><b>用&nbsp;户&nbsp;名:</b></td>
<td>&nbsp;</td>
<td colspan="2">
<input type="text" name="logname"value="">
</td>
</tr>

<tr>
<td align="right"><b>登录密码:</b></td>
<td>&nbsp;</td>
<td colspan="2">
<input type="password" name="passwd1"value="">
</td>
</tr>

<tr>
<td align="right"><b>密码确认:</b></td>
<td>&nbsp;</td>
<td colspan="2">
<input type="password" name="passwd2"value="">
</td>
</tr>

<tr>
<td align="right"><b>电子邮件:</b></td>
<td>&nbsp;</td>
<td colspan="2">
<input type="text" name="email"value="">
</td>
</tr>

<tr>
<td align="right"><b>性&nbsp;&nbsp;&nbsp;&nbsp;别:</b></td>
<td>&nbsp;</td>
<td colspan="2">
<input type="radio" name="Gender" value="0"checked>
男
<input type="radio" name="gender"value="1">
女
</td>
</tr>

<tr>
<td align="right">联系电话:</td>
<td>&nbsp;</td>
<td colspan="2">
<input type="text" name="phone"value="">
</td>
</tr>

<tr>
<td align="right">家庭住址:</td>
<td>&nbsp;</td>
<td colspan="2">
<input type="text" name="address"value="">
</td>
</tr>
<tr>
<td align="center" colspan="4">
<input type="button" value="提交"  onclick="sub( )">
  <script language="javascript">
     function sub()
     {
       if(document.form1.logname.value=="")
        {
          window.alert("请输入用户名！");
          window.form1.logname.focus();
          return false; 
        }
       if(document.form1.realname.value=="")
        {
           window.alert("请填写您的姓名！");
           window.form1.realname.focus();
           return false;
        }
       if(document.form1.passwd1.value=="")
        {
           window.alert("请输入密码！");
           window.form1.passwd1.focus();
           return false;
        }
       if(document.form1.passwd1.value!=document.form1.passwd2.value)
        {
           window.alert("两次输入的密码不一致，请重新输入！");
           window.form1.passwd2.focus();
           return false;
        }
       if(document.form1.email.value=="")
        {
           window.alert("请输入您的电子信箱！");
           window.form1.email.focus();
           return false;
        }
       document.form1.submit();
     }
</script>
  </td>
</tr>
</form>
</table>
</body>
</html>
