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时间不长,以后会慢慢的把自己写的程序通过类来完成,但这需要一个过程,我觉得基础比较重要现在我要把基础的东西写好点!哈哈!!