写了一个比较简单的会员注册页面,带会员已经存在验证,发上来大家给点建议

php的程序如下:

<?php
require_once("conn_inc.php");
require_once("smarty_inc.php");
if ($_POST['submit']) {
$name= $_POST['name'];
$pass= $_POST['pass'];
$password= $_POST['password'];
$sex= $_POST['sex'];
$mail= $_POST['mail'];
$content= $_POST['content'];
$query=@mysql_query("select * from login where name='$name' ");
if ($row=@mysql_fetch_array($query)) {
echo "<script>alert('用户名已经存在,请重新填写用户名!')</script>";
echo "<script>location.href='login.php'</script>";
}else {
 $sql="insert into `login` (name,pass,password,sex,mail,content,login_date)
 values ('$name','$pass','$password','$sex','$mail','$content',now())";
 $query=mysql_query($sql);
 if ($query) {
 echo "<script>alert('插入成功!')</script>";
 echo "<script>location.href='category_list.php'</script>";
 }
}
}
$smarty->display("login.tpl.html");
?>

模板程序如下:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
{literal}
<SCRIPT language=JavaScript>
<!--
function checkform()
{

    if (addnew.name.value=="") {
              alert("请输入用户名!");
              addnew.name.focus();             
                  return (false);
  }
    if (addnew.pass.value=="") {
              alert("请输入密码!");
              addnew.pass.focus();             
                  return (false);
  }
  if(addnew.password.value==""){
alert("请输入您的确认密码!");
document.addnew.password.focus();
return false;
}
if(addnew.mail.value=="")
{
alert("请输入电子邮箱");
document.addnew.mail.focus();
return false;

}
 
if(addnew.content.value=="")
{
alert("请输入内容介绍!");
document.addnew.content.focus();
return false;
}
  return true;
}
//-->
</SCRIPT>
{/literal}
<form name="addnew" id="form1" method="post" action="" οnsubmit="return checkform()">
{strip}
<table border="1" align="center" width="50%">
<tr>
<td>用户名:</td>
<td><input type="text" name="name" size="30"></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="pass" size="30"></td>
</tr>
<tr>
<td>密码确认:</td>
<td><input type="password" name="password" size="30"></td>
</tr>
<tr>
<td>性别:</td>
<td>
<input type="radio" value="男" name="sex" checked>男
<input type="radio" value="女" name="sex">女
</td>
</tr>
<tr>
<td>注册邮箱:</td>
<td><input name="mail" type="text" size="30"></td>
</tr>
<tr>
<td>详细介绍</td>
<td><textarea rows="10" cols="40" name="content"></textarea></td>
</tr>
<tr><td colspan="2"><input  type="submit" value="用户提交" name="submit"></td></tr>
</table>
{/strip}
</form>
</body>
</html>

 


备注:以上程序都是本人测试过的,没有BUG,可能写的不怎么好,请大家越来,因为我写PHP时间不长,以后会慢慢的把自己写的程序通过类来完成,但这需要一个过程,我觉得基础比较重要现在我要把基础的东西写好点!哈哈!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值