php+Mysql页面注册代码

时间:2023-03-09 17:36:31
php+Mysql页面注册代码
页面设置代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="register_post.php" method="post">
<table>
<tr>
<td>用户名:</td>
<td><input type="text" name="uname" placeholder="请输入账号"></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="pwod" placeholder="请输入密码"></td>
</tr>
</table>
<input type="submit" value="注册">
</form>
</body>
</html> 注册处理页面代码:
<?php
/**
* Created by xx.
* User: msi
* Date: 2017/10/24
* Time: 11:00
*/ header("content-type:text/html; charset=utf-8"); //引入前面的DBDA方法集文件
require_once "../DBDA.class.php";
$db = new DBDA();
var_dump($_POST);
if(!empty($_POST)) {
$uname = $_POST["uname"];
//查询用户注册的用户名是否和数据库已有的用户名重复,并返回查询结果;
$sql = "select * from t_user WHERE uname = '{$uname}'";
// echo $sql;
$result = $db->strQuery($sql); //}
if ($result != "0") {
exit("用户名字被占用");
} else {
$sql_insert = "insert into t_user(uname,pwod) VALUES ('{$_POST["uname"]}','{$_POST["pwod"]}')";
echo $sql_insert;
$result2 = $db->Query($sql_insert, 0);
var_dump($result2);
}
}
//echo "张三";
//echo $_POST['uname'];
//echo $_POST['pwod'];
?> <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body> </body>
</html>
这样就完成啦!