签到 登录注册注意事项

注册、编辑用户信息:

代码如下:

注册
处理代码
页面代码

注册页面逻辑:

1、页面表单获取用户输入内容

(1) 在js中判断格式是不是正确

(2) 在js中提交表单

1、将获取的数据传到php页面进行操作 存数据库

A、判断用户名存不存在

B、存在注册失败

不存在就插入数据库

 

管理员登录并修改:

 

 1 <?php
 2     //创建数据库连接备用
 3     $db = new MySQLi("localhost","root","123","z_test");
 4     !mysqli_connect_error() or die("连接失败");
 5     $db->query("set names utf8");
 6     //获取用户名
 7     $uid = $_GET["uid"];
 8     $detres = $_GET["detres"];
 9     if($detres == "1"){
10         echo "删除失败";
11     }
12 
13     //获取 z_test.user
14     $sql = "select * from user";
15     $result = $db->query($sql);
16     $attr = $result->fetch_all();
17 
18     //var_dump($attr);
19     foreach($attr as $v){ 
20         echo "<tr><td></td></tr>";
21     }
22 ?>
23 <!doctype html>
24 <html>
25     <head>
26         <meta charset="utf-8">
27         <title>无标题文档</title>
28     </head>
29 
30     <body>
31         欢迎你:<?php echo $uid ?><br>
32         <table border="1" width="100%">
33             <tr>
34                 <th>用户名</th>
35                 <th>密码</th>
36                 <th>操作</th>
37             </tr>
38 
39             <?php    foreach($attr as $v){ ?>
40                 <tr>
41                     <td><?php echo $v[2] ?></td>
42                     <td><?php echo $v[3] ?></td>
43                     <td>
44                         <button uid = "<?php echo $v[0] ?>" onClick="del(this)">删除</button>
45         
46                     </td>
47                 </tr>
48             <?php } ?>
49         </table>
50         <a href="add.php">添加</a>
51     </body>
52 </html>
53 <script>
54     /**
55     功能:点击删除跳转到删除处理页面执行删除操作
56     参数:标签本身对象
57     返回:无
58     */
59     function del(obj){
60         if(confirm("确定删除吗?")){
61             location.href = "delchuli.php?uid="+obj.getAttribute("uid");
62         }
63         
64     }
65 </script>
list
数据的
<?php
//连接数据库备用
$db = new MySQLi("localhost","root","123","z_test");
!mysqli_connect_error() or die("连接失败");
$db->query("set names utf8");



//获取用户输入的信息
$uid = $_POST["uid"];
$pwd = $_POST["pwd"];

//根据用户名查询密码的sql语句
$sql = "select password from user where name = '$uid'";
$result = $db->query($sql);
//将结果集转为数组
$attr = $result->fetch_row();

//判断用户输入的密码和数据库中的密码是否一致
if($attr[0] == $pwd){
	//一致说明用户输入正确可以登录 跳转到列表页 将用户名作为参数传过去
	header("location:list.php?uid=".$uid);
}else{//否则就返回登录页面 传一个错误标志回去
	header("location:login.php?error=1");
}

  数据的添加:

<?php
//连接数据库备用
$db = new MySQLi("localhost","root","123","z_test");
!mysqli_connect_error() or die("连接失败");
$db->query("set names utf8");


//获取用户输入的信息
$uid = $_POST["uid"];
$pwd = $_POST["pwd"];

//根据添加用户  需要加判断
$sql = "insert into  user(name,password) values('$uid','$pwd')";
$result = $db->query($sql);

if($result){
	header("location:list.php");
}else{
	header("location:add.php");
}

 出咯数据代码:

<?php
//连接数据库备用
$db = new MySQLi("localhost","root","123","z_test");
!mysqli_connect_error() or die("连接失败");
$db->query("set names utf8");



//获取用户输入的信息
$uid = $_POST["uid"];
$pwd = $_POST["pwd"];

//根据用户名查询密码的sql语句
$sql = "select password from user where name = '$uid'";
$result = $db->query($sql);
//将结果集转为数组
$attr = $result->fetch_row();

//判断用户输入的密码和数据库中的密码是否一致
if($attr[0] == $pwd){
	//一致说明用户输入正确可以登录 跳转到列表页 将用户名作为参数传过去
	header("location:list.php?uid=".$uid);
}else{//否则就返回登录页面 传一个错误标志回去
	header("location:login.php?error=1");
}

  标准的连接数据库代码:

<?php
//连接数据库备用
$db = new MySQLi("localhost","root","123","z_test");
!mysqli_connect_error() or die("连接失败");
$db->query("set names utf8");

 

posted @ 2018-02-05 22:52  邹少聪  阅读(387)  评论(0编辑  收藏  举报