【php开源代码栏目提醒】:网学会员php开源代码为您提供register_pre_validate.php参考,解决您在register_pre_validate.php学习中工作中的难题,参考学习。
<?php
$username = $_POST['username'];
$pwd = $_POST['pwd'];
$repeat_pwd = $_POST['repeat_pwd'];
$name = $_POST['name'];
$email = $_POST['email'];
if (!empty($username) ) { // 用户填写了数据才执行数据库操作
// 调用mysqli的构造函数建立连接,同时选择使用数据库'test'
$db = @new mysqli("127.0.0.1", "developer", "123456", "test");
// 检查数据库连接
if (
mysqli_connect_errno()) {
echo "数据库连接失败!<br>\n";
echo mysqli_connect_error();
exit; // 退出
程序,后面的所有语句将不再执行
}
$sql = "SELECT * FROM t_user WHERE f_username='$username'";
$rs = $db->query($
sql);
if ($rs && $rs->num_rows > 0) {
echo "<font color='red' size='5'>该用户名已被注册,请换一个重试!</font><br>\n";
}
else {
$sql = "INSERT INTO t_user (f_username, f_password, f_name, f_email) VALUES";
$sql .= "('$username', '$pwd', '$name', '$email')";
$rs = $db->query($sql);
if (!$rs) {
$db->close(); // 关闭数据库连接
echo '数据记录插入失败!';
exit;
}
echo "<font color='red' size='5'>恭喜您
注册成功!</font><br>\n";
}
// 关闭数据库连接
$db->close();
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Registering form</title>
</head>
<body>
<?php
if (!empty($username) ) {
echo "您填写的信息是:<br>\n";
echo "用户名: $username <br>\n";
echo "密码: $pwd <br>\n";
echo "重复密码: $repeat_pwd <br>\n";
echo ": $name <br>\n";
echo "Email: $email <br>\n";
}
?>
<form name="frmRegister" method="post" action="register.php">
<table width="330" border="0" align="center" cellpadding="5" bgcolor="#eeeeee">
<tr>
<td width="40%">用户名:</td>
<td><input name="username" type="text" id="username"> </td>
</tr>
<tr>
<td>密码:</td>
<td><input name="pwd" type="pass
word" id="pwd"></td>
</tr>
<tr>
<td>重复密码:</td>
<td><input name="repeat_pwd" type="password" id="repeat_pwd"></td>
</tr>
<tr>
<td>:</td>
<td><input name="name" type="text" id="name"></td>
</tr>
<tr>
<td>Email:</td>
<td><input name="email" type="text" id="email"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="Submit" value="提交">
<input type="reset" name="reset" value="重置"></td>
</tr>
</table>
</form>
</body>
</html>