@@ -11,34 +11,27 @@ class ChkInput{ //定义chkinput 类
11
11
var $ name ; //定义成员变量
12
12
var $ pwd ;
13
13
14
- // function chk_input($x,$y){ //定义成员方法
15
- // $this->name = $x;
16
- // $this->pwd = $y;
17
- // echo $x.'<br>',$y;
18
- // }
19
14
function checkipput ($ name ,$ pwd ){ // 定义方法,完成用户注册
20
15
$ this ->name = $ name ;
21
16
$ this ->pwd = $ pwd ;
22
17
echo $ name .'<br> ' .$ pwd ;
23
- // include "conn.php"; //通过include 调用数据库连接文件
24
18
$ conn = mysqli_connect ("localhost " ,"root " ,"" );
25
19
mysqli_select_db ($ conn ,'test11 ' ) or die ('数据库访问错误 ' .mysqli_errno ($ conn ));
20
+ mysqli_query ($ conn ,"SET AUTOCOMMIT=1 " );
26
21
mysqli_query ($ conn ,"set names utf8_general_ci " );
27
- // 执行查询
28
- // mysqli_query($conn,"SELECT * FROM tb_user");
29
- // $info = mysqli_query($conn,"insert into tb_user('user','password')values ($name,$pwd)");
30
- $ info = mysqli_query ($ conn ,"INSERT INTO tb_user (id,user,password) VALUES ('3', $ name, $ pwd) " );
31
- if ($ info == false ){ //如果添加操作的返回结果,给出提示信息
22
+ $ info = "INSERT INTO tb_user (user,password) VALUES (' $ name',' $ pwd') " ;
23
+ if (mysqli_query ($ conn ,$ info )){ //如果添加操作的返回结果,给出提示信息
24
+ $ _SESSION ['admin_name ' ] = $ name ; //注册成功后,将用户名赋给SESSION变量
32
25
mysqli_close ($ conn );
33
- echo "<script>alert('会员注册失败!');history.back()</script> " ;
26
+ echo "<script>alert('恭喜您,注册成功!');window.location.href='index.php'</script> " ;
27
+
34
28
}else {
35
- $ _SESSION [ ' admin_name ' ] = $ this -> name ; //注册成功后,将用户名赋给SESSION变量
29
+ echo " <script>alert('会员注册失败!');history.back()</script> " ;
36
30
mysqli_close ($ conn );
37
- echo " <script>alert('恭喜您,注册成功!');window.location.href='index.php'</script> " ;
31
+
38
32
}
39
33
}
40
34
41
35
}
42
36
$ obj = new ChkInput (); //实例化类
43
- //$obj->chk_input(trim($_POST['username']),trim(md5($_POST['password'])));
44
- $ obj ->checkipput (trim ($ _POST ['username ' ]),trim ($ _POST ['password ' ]));//返回对象调用方法执行注册操作
37
+ $ obj ->checkipput (trim ($ _POST ['username ' ]),trim (md5 ($ _POST ['password ' ])));//返回对象调用方法执行注册操作
0 commit comments