Mẫu đăng ký Bootstrap PHP MySQL

Trong bài đăng này, Chúng tôi phải chia sẻ Cách tạo Biểu mẫu đăng ký trong CodeIgniter và Bootstrap Framework cùng với Cơ sở dữ liệu MySQL và sử dụng MD5 là thuật toán mã hóa 128 bit. Bằng cách sử dụng này, người dùng có thể dễ dàng đăng ký, tên người dùng, tên, họ, email, mật khẩu. Sau khi gửi biểu mẫu, dữ liệu sẽ được lưu trữ trong bảng cơ sở dữ liệu. Đây là một ví dụ rất đơn giản, bạn chỉ cần sao chép-dán và thay đổi theo yêu cầu của mình

cũng đọc. Tạo Mô-đun đăng ký và đăng nhập đầy đủ tính năng trong CodeIgniter

Trước khi bắt đầu triển khai Tạo đăng ký bằng CodeIgniter, hãy xem cấu trúc tệp

  • tạo-đăng ký-biểu mẫu-với-codeigniter
    • đăng kí
      • cấu hình
        • tự động tải. php
        • hằng số. php
        • tuyến đường. php
      • người mẫu
        • Người dùng_model. php
      • bộ điều khiển
        • người dùng. php
      • lượt xem
        • người dùng
          • Cảm ơn. php
          • mục lục. php
        • mẫu
          • tiêu đề. php
          • cuối trang. php
    • hệ thống
    • mục lục. php
    • tài sản
      • hình ảnh
      • css
        • Phong cách. css

Bước 1. Tạo cơ sở dữ liệu MySQL và bảng để đăng ký người dùng

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

  TẠO BẢNG `người dùng` (

    `user_id` int(12) NOT NULL,

    `tên` varchar(50) DEFAULT NULL,

    `user_name` varchar(50) NOT NULL,

    `email` varchar(255) NOT NULL,

    `mật khẩu` varchar(255) NOT NULL,

    `trạng thái` int(1) NOT NULL

  ) ĐỘNG CƠ = InnoDB DEFAULT CHARSET=latin1;

 

  THAY ĐỔI BẢNG `người dùng`

    THÊM CHỮ CHÍNH KEY (`user_id`),

    THÊM ĐỘC NHẤT KEY `email` (`email`);

 

  THAY ĐỔI BẢNG `người dùng`

    SỬA ĐỔI `user_id` int(12) NOT NULL AUTO_INCREMENT;

  CAM KẾT;

?>

Bước 2. Tạo một tệp mô hình Đăng ký người dùng

Tạo một tệp mô hình có tên “Users_model. php” bên trong thư mục “application/models”

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

 

/**

* Mô tả Bộ điều khiển xuất khẩu

*

* @author Nhóm TechArise

*

* @email  info@techarise. com

*/

được xác định('BASEPATH') hoặc exit('No direct script access allowed');

 

lớp Users_model mở rộng CI_Model

{

  // khai báo biến riêng tư

  riêng tư $_userID;

  riêng tư $_name;

  riêng tư $_userName;

  riêng tư $_email;

  riêng tư $_password;

  riêng tư $_status;

 

  chức năng công khai setUserID($userID)

  {

    $this - >_userID = $userID;

  }

  hàm công khai setName($name)

  {

    $this - >_name = $name;

  }

  hàm công khai setUserName($userName)

  {

    $this - >_userName = $userName;

  }

  chức năng công khai setEmail($email)

  {

    $this - >_email = $email;

  }

  chức năng công khai setPassword($password)

  {

    $this - >_password = $password;

  }

  hàm công khai setStatus($status)

  {

    $this - >_status = $status;

  }

 

  hàm công khai tạo Người dùng()

  {

    $data = mảng(

      'name' = > $this->_name,

      'email' = > $this->_email,

      'user_name' = > $this->_userName,

      'mật khẩu' = > $this->_password,

      'status' = > $this->_status,

    );

    $this - >db->insert('users', $data);

    return $this - >db->insert_id();

  }

}

 

?>

Bước 3. Tạo tệp điều khiển Đăng ký người dùng

Tiếp theo, tạo một tệp điều khiển có tên “Người dùng. php” bên trong thư mục “application/controllers”

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

 

/**

* Mô tả Bộ điều khiển xuất khẩu

*

* @author Nhóm TechArise

*

* @email  info@techarise. com

*/

được xác định('BASEPATH') hoặc exit('No direct script access allowed');

 

lớp Người dùng mở rộng CI_Controller

{

 

  hàm công khai __construct()

  {

    cha mẹ. . __construct();

    $this - >tải->model('Users_model', 'user');

  }

  // Trang tổng quan

  hàm công khai chỉ mục()

  {

    $data['title'] = 'Dashboard - Tech Arise';

    $data['metaDescription'] = 'Dashboard';

    $data['metaKeywords'] = 'Dashboard';

    $this - >tải->view('users/thank-you', $data);

  }

  // Đăng ký

  chức năng công khai đăng ký()

  {

    $data['title'] = 'Register - Tech Arise';

    $data['metaDescription'] = 'Register';

    $data['metaKeywords'] = 'Register';

    $this - >tải->view('users/index', $data);

  }

  // Thanh ghi hành động

  chức năng công khai actionRegister()

  {

    $this - >tải->library('form_validation');

   // tên trường, thông báo lỗi, quy tắc xác thực

    $this - >form_validation->set_rules('name', 'Name', 'required');

    $this - >form_validation->set_rules('username', 'User Name', 'trim|required|min_length[4]');

    $this - >form_validation->set_rules('email', 'Your Email', 'trim|required|valid_email');

    $this - >form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]');

    $this - >form_validation->set_rules('confirm_password', 'Password Confirmation', 'trim|required|matches[password]');

 

    if ($this - >form_validation->run() == FALSE) {

      $this - >đăng ký();

    } else {

      // giá trị đăng

      $name = $this - >input->post('name');

      $username = $this - >input->post('username');

      $email = $this - >input->post('email');

      $password = $this - >input->post('password');

      // đặt giá trị bài đăng

      $this - >người dùng->setName($name);

      $this - >người dùng->setUserName($username);

      $this - >người dùng->setEmail($email);

      $this - >người dùng->setPassword(MD5($password));

      $this - >người dùng->setStatus(1);

      // chèn giá trị vào cơ sở dữ liệu

      $this - >người dùng->createUser();

      chuyển hướng('người dùng/chỉ mục')<;

    }

  }

}

 

?>

Bước 4. Tạo một tệp xem để đăng ký người dùng

Tạo một tệp xem có tên là chỉ mục. php” bên trong thư mục “application/views/users”

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

$this->load< $this->load->view('templates/header'); ?>

<vai trò chính = "chính" class="container mcontainer">

    <div class = "wrapper">

        <hình thức hành động = " echo base_url(); ?>users/actionregister" method="post" id="loginform" name="Login_Form" class="form-signin" method="POST">

            <h4 lớp = "form-signin-heading">Create Registration Form with CodeIgniter</h4>

            ?php if (validation_errors()) { ?>

                        <div lớp = "alert alert-danger">

                    ?php echo validation_errors(); ?>

                < / div>

            ?php } ?>

            <div class = "form-group">

                <nhãn cho = "name">Name</label>

                <đầu vào loại = "text" class="form-control" id="name" name="name" placeholder="Name*" required />

            < / div>

 

            <div class = "form-group">

                <nhãn cho = "name">User Name</label>

                <đầu vào loại = "text" class="form-control" id="user-name" name="username" placeholder="User Name*" required />

            < / div>

 

            <div class = "form-group">

                <nhãn cho = "name">Email</label>

                <đầu vào loại = "email" class="form-control" id="email" name="email" placeholder="Email*" required />

            < / div>

 

            <div class = "form-group">

                <nhãn cho = "name">Password</label>

                <đầu vào loại = "password" class="form-control" id="password" name="password" placeholder="Password" required />

            < / div>

 

            <div class = "form-group">

                <nhãn cho = "exampleInputPassword1">Confirm Password</label>

                <đầu vào loại = "password" class="form-control" id="password-confirm" name="confirm_password" placeholder="Confirm Password" required />

            < / div>

            <nút loại = "submit" class="btn btn-primary" style="float:right">Đăng ký< / button>

        < / biểu mẫu>

    < / div>

< / chính>

$this->load< $this->load->view('templates/footer'); ?>

Bước 5. Tạo một trang cảm ơn

Tạo một tệp xem có tên là cảm ơn bạn. php” bên trong thư mục “application/views/users”

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

  ?php

$this - >load - >view('templates/header');

?>

<vai trò chính = "chính" class="container mcontainer">

    <div class = "wrapper thank-you-page">

        <div lớp = "thank-you-pop">

            <img src = " echo HTTP_IMAGES_PATH; ?>tick.png" alt = "">

            <h1>Cảm ơn You!< / h1>

            <p> submission is received and we will contact you soon</p>

        < / div>

        <giờ>

        <div lớp = "row">

            <div class = "col-lg-8 offset-2">

                <a href = " echo base_url(); ?>register" class="btn btn-sm btn-primary" style="float:right"><i lớp="fa fa-user"></i> Register</a>

                <a lớp = "btn btn-primary btn-sm" href=" echo base_url(); ?>create-registration-form-with-codeigniter-and-bootstrap/"><i class="fa fa-mail-reply"></i> Back To Tutorial</a>

            < / div>

        < / div>

    < / div>

< / chính>

$this - >load - >view('templates/footer');

?>

Vì vậy, hãy mở “application/config/routes. php” và thêm mã như dưới đây

1

2

3

4

  // tuyến đường

  $route['default_controller'] = 'users/register';

?>

cũng đọc. Tạo Mô-đun đăng ký và đăng nhập đầy đủ tính năng trong CodeIgniter

Tải xuống bản trình diễn