Làm cách nào chúng tôi có thể lưu trữ dữ liệu trong php mà không cần cơ sở dữ liệu?

Hướng dẫn này cho biết cách lưu dữ liệu biểu mẫu vào cơ sở dữ liệu MySQL bằng PHP. Một sự hiểu biết cơ bản của cả hai là cần thiết

Bắt đầu nào

  1. Tạo cơ sở dữ liệu và bảng của bạn.
    Các cột trong bảng của bạn sẽ phụ thuộc vào cấu trúc biểu mẫu của bạn. Xem hướng dẫn này để xem tên trường hoặc khóa đăng của biểu mẫu nếu bạn không chắc chắn nên thêm cột nào vào bảng cơ sở dữ liệu của mình.
  2. Đối với hướng dẫn này, hãy nhớ thêm cột “submission_id” vào bảng của bạn.
    Trong biểu mẫu liên hệ mẫu này, bảng có dạng như sau trong phpMyAdmin.

Ghi chú. Quá trình tạo hoặc chỉnh sửa cơ sở dữ liệu của bạn sẽ phụ thuộc vào thiết lập máy chủ hoặc máy chủ lưu trữ web của bạn. Liên hệ với bộ phận hỗ trợ của nhà cung cấp của bạn để được hỗ trợ

biểu mẫu HTML. Trước tiên, chúng tôi tạo một biểu mẫu HTML cần lấy đầu vào của người dùng từ bàn phím. Biểu mẫu HTML là một tài liệu lưu trữ thông tin của người dùng trên máy chủ web bằng các điều khiển tương tác. Một biểu mẫu HTML chứa các loại thông tin khác nhau như tên người dùng, mật khẩu, số liên lạc, id email, v.v.

Các phần tử được sử dụng trong biểu mẫu HTML là hộp kiểm, hộp nhập liệu, nút radio, nút gửi, v.v. Với sự trợ giúp của các yếu tố này, thông tin của người dùng được gửi trên máy chủ web. Thẻ biểu mẫu được sử dụng để tạo biểu mẫu HTML

cú pháp

 Form Elements.. 

hoặc

Để chuyển các giá trị sang trang tiếp theo, chúng tôi sử dụng tên trang với cú pháp sau. Chúng ta có thể sử dụng phương thức GET hoặc POST để gửi dữ liệu đến máy chủ

    Form Elements...

kết nối cơ sở dữ liệu. Tập hợp các dữ liệu liên quan được gọi là cơ sở dữ liệu. XAMPP là viết tắt của đa nền tảng, Apache, MySQL, PHP và Perl. Đây là một trong những máy chủ cục bộ nhẹ, đơn giản để phát triển trang web. Trong PHP, chúng ta có thể kết nối với cơ sở dữ liệu bằng máy chủ web localhost XAMPP

cú pháp

PHP




    Form Elements...
32

 

    Form Elements...
33
    Form Elements...
34
    Form Elements...
35
    Form Elements...
36

    Form Elements...
37
    Form Elements...
34
    Form Elements...
39
    Form Elements...
36

    Form Elements...
1
    Form Elements...
34
    Form Elements...
3
    Form Elements...
36

    Form Elements...
5
    Form Elements...
34
    Form Elements...
7____136

 

    Form Elements...
9

    Form Elements...
320
    Form Elements...
34
    Form Elements...
322
    Form Elements...
323
    Form Elements...
33
    Form Elements...
325

    Form Elements...
326
    Form Elements...
37____1325
    Form Elements...
1
    Form Elements...
325
    Form Elements...
5
    Form Elements...
332

 

    Form Elements...
333

    Form Elements...
334
    Form Elements...
335
    Form Elements...
320
    Form Elements...
337

    Form Elements...
326
    Form Elements...
339____1335
    Form Elements...
341

    Form Elements...
342
    Form Elements...
343
    Form Elements...
320
    Form Elements...
345

    Form Elements...
346

 

    Form Elements...
347
    Form Elements...
348

    Form Elements...
326
    Form Elements...
335
    Form Elements...
351
    Form Elements...
325
    Form Elements...
353
    Form Elements...
325
    Form Elements...
355
    Form Elements...
356

 

    Form Elements...
334
    Form Elements...
335
    Form Elements...
320
    Form Elements...
360
    Form Elements...
361
    Form Elements...
362

    Form Elements...
326
    Form Elements...
364
    Form Elements...
365
    Form Elements...
36

________ 1346 ________ 1368 ________ 1369

    Form Elements...
326
    Form Elements...
364
    Form Elements...
372
    Form Elements...
343
    Form Elements...
361
    Form Elements...
343
    Form Elements...
376
    Form Elements...
343
    Form Elements...
320
    Form Elements...
379

    Form Elements...
346

  

Cách lấy dữ liệu biểu mẫu. Chúng tôi sẽ thu thập dữ liệu biểu mẫu được gửi qua biểu mẫu HTML. Phương thức PHP $_REQUEST là một biến siêu toàn cầu PHP được sử dụng để thu thập dữ liệu sau khi gửi biểu mẫu HTML

cú pháp

PHP




    Form Elements...
32

 

    Form Elements...
334
    Form Elements...
335
    Form Elements...
344
    Form Elements...
345
    Form Elements...
346
    Form Elements...
347
    Form Elements...
348
    Form Elements...
349

 

    Form Elements...
326
    Form Elements...
391

    Form Elements...
326
    Form Elements...
393
    Form Elements...
34
    Form Elements...
395
    Form Elements...
345
    Form Elements...
397
    Form Elements...
398

 

    Form Elements...
326
    Form Elements...
334
    Form Elements...
335
    Form Elements...
02
    Form Elements...
335
    Form Elements...
393
    Form Elements...
05

________ 1342 ________ 1364 ________ 108 ________ 136

    Form Elements...
326
    Form Elements...
346
    Form Elements...
368
    Form Elements...
369

    Form Elements...
342
    Form Elements...
364
    Form Elements...
393
    Form Elements...
36

    Form Elements...
326
    Form Elements...
346

    Form Elements...
346

    Form Elements...
21

 

    Form Elements...
22

    Form Elements...
320
    Form Elements...
24

 

    Form Elements...
21

 
 

Hoàn thành các bước để thiết kế dự án

  • Khởi động máy chủ XAMPP
  • Mở localhost/phpmyadmin trong trình duyệt web của bạn
  • Tạo cơ sở dữ liệu tên nhân viên và bảng tên trường đại học
  • Viết mã HTML và PHP trong Notepad của bạn trong một thư mục cụ thể
  • Gửi dữ liệu thông qua Biểu mẫu HTML
  • Xác minh kết quả

Các bước chi tiết.  

  • Khởi động XAMPP Server bằng cách mở XAMPP và nhấp vào XAMPP Start.
     

  • Mở localhost/phpmyadmin trong trình duyệt web của bạn và tạo cơ sở dữ liệu với tên cơ sở dữ liệu là nhân viên và nhấp vào tạo.
     

  • Sau đó tạo bảng tên trường đại học.
     

  • Nhập các cột và nhấp vào lưu

  • Bây giờ hãy mở Notepad và bắt đầu viết mã PHP và lưu nó dưới dạng chỉ mục. php và mở notepad khác và lưu nó dưới dạng chèn. php Lưu cả hai tệp vào một thư mục dưới htdocs

tên tệp. mục lục. php

PHP




    Form Elements...
26

    Form Elements...
27
    Form Elements...
28
    Form Elements...
29

    Form Elements...
30
    Form Elements...
31

    Form Elements...
32
    Form Elements...
33

    Form Elements...
30
    Form Elements...
35

    Form Elements...
30
    Form Elements...
37

    Form Elements...
32
    Form Elements...
39

    Form Elements...
40
    Form Elements...
41

    Form Elements...
40
    Form Elements...
43
    Form Elements...
44
    Form Elements...
45
    Form Elements...
46
    Form Elements...
29

    Form Elements...
48

    Form Elements...
49

    Form Elements...
50
    Form Elements...
51
    Form Elements...
52
    Form Elements...
34
    Form Elements...
54
    Form Elements...
55

    Form Elements...
50
    Form Elements...
57
    Form Elements...
58
    Form Elements...
59
    Form Elements...
60
    Form Elements...
61
    Form Elements...
54
    Form Elements...
29

    Form Elements...
48
    Form Elements...
65

 

    Form Elements...
48

    Form Elements...
49

    Form Elements...
50
    Form Elements...
51
    Form Elements...
52
    Form Elements...
34
    Form Elements...
72
    Form Elements...
73

    Form Elements...
50
    Form Elements...
57
    Form Elements...
58
    Form Elements...
59
    Form Elements...
78
    Form Elements...
61
    Form Elements...
72
    Form Elements...
29

    Form Elements...
48
    Form Elements...
65

 

    Form Elements...
48

    Form Elements...
49

    Form Elements...
50
    Form Elements...
51
    Form Elements...
52
    Form Elements...
34
    Form Elements...
90
    Form Elements...
91

    Form Elements...
50
    Form Elements...
57
    Form Elements...
58
    Form Elements...
59
    Form Elements...
96
    Form Elements...
61
    Form Elements...
90
    Form Elements...
29

    Form Elements...
48
    Form Elements...
65

 

    Form Elements...
48

    Form Elements...
49

    Form Elements...
50
    Form Elements...
51
    Form Elements...
52
    Form Elements...
34
    Form Elements...
3208
    Form Elements...
3209

    Form Elements...
50
    Form Elements...
57
    Form Elements...
58
    Form Elements...
59
    Form Elements...
3214
    Form Elements...
61
    Form Elements...
3208
    Form Elements...
29

    Form Elements...
48
    Form Elements...
65

 

    Form Elements...
48

    Form Elements...
49

    Form Elements...
50
    Form Elements...
51
    Form Elements...
52
    Form Elements...
34
    Form Elements...
3226
    Form Elements...
3227

    Form Elements...
50
    Form Elements...
57
    Form Elements...
58
    Form Elements...
59
    Form Elements...
3232
    Form Elements...
61
    Form Elements...
3226
    Form Elements...
29

    Form Elements...
48
    Form Elements...
65

 

    Form Elements...
48
    Form Elements...
57____13240
    Form Elements...
3241
    Form Elements...
3242
    Form Elements...
29

    Form Elements...
40
    Form Elements...
3245

    Form Elements...
32
    Form Elements...
3247

    Form Elements...
30____13249

    Form Elements...
3250

  

tên tệp. chèn. php

PHP




    Form Elements...
26

    Form Elements...
3252

 

    Form Elements...
31

    Form Elements...
326
    Form Elements...
3255

    Form Elements...
35

 

    Form Elements...
37

    Form Elements...
326
    Form Elements...
39

    Form Elements...
342
    Form Elements...
32

 

    Form Elements...
342
    Form Elements...
3263

    Form Elements...
342
    Form Elements...
3265

_______1342____13267

    Form Elements...
342
    Form Elements...
3269

    Form Elements...
342
    Form Elements...
320
    Form Elements...
3272
    Form Elements...
35
    Form Elements...
325
    Form Elements...
3275
    Form Elements...
325
    Form Elements...
3277
    Form Elements...
325
    Form Elements...
3279
    Form Elements...
332

    Form Elements...
342

    Form Elements...
342
    Form Elements...
333

    Form Elements...
342
    Form Elements...
334
    Form Elements...
335
    Form Elements...
320
    Form Elements...
3288

    Form Elements...
48
    Form Elements...
339____1335
    Form Elements...
3292

    Form Elements...
3293____13294

    Form Elements...
342
    Form Elements...
346

    Form Elements...
342

    Form Elements...
342
    Form Elements...
3299

    Form Elements...
342
    Form Elements...
3301
    Form Elements...
3302
    Form Elements...
395
    Form Elements...
345
    Form Elements...
3305
    Form Elements...
398

    Form Elements...
342
    Form Elements...
3308
    Form Elements...
34
    Form Elements...
395
    Form Elements...
345
    Form Elements...
3312
    Form Elements...
398

    Form Elements...
342
    Form Elements...
3315
    Form Elements...
3302
    Form Elements...
395
    Form Elements...
345
    Form Elements...
3319
    Form Elements...
398

    Form Elements...
342
    Form Elements...
3322
    Form Elements...
34
    Form Elements...
395
    Form Elements...
345
    Form Elements...
3326
    Form Elements...
398

    Form Elements...
342
    Form Elements...
3329
    Form Elements...
34
    Form Elements...
395
    Form Elements...
345
    Form Elements...
3333
    Form Elements...
398

    Form Elements...
342

    Form Elements...
342
    Form Elements...
3337

    Form Elements...
342
    Form Elements...
3339

    Form Elements...
342
    Form Elements...
361
    Form Elements...
3342
    Form Elements...
3343
    Form Elements...
325

    Form Elements...
48
    Form Elements...
3346
    Form Elements...
325
    Form Elements...
3348
    Form Elements...
325
    Form Elements...
3350
    Form Elements...
325
    Form Elements...
3352
    Form Elements...
3353

    Form Elements...
342

    Form Elements...
342
    Form Elements...
334
    Form Elements...
3357
    Form Elements...
320
    Form Elements...
325
    Form Elements...
361
    Form Elements...
3361

    Form Elements...
48
    Form Elements...
364
    Form Elements...
3364

    Form Elements...
3293
    Form Elements...
343
    Form Elements...
3367

    Form Elements...
3293
    Form Elements...
343
    Form Elements...
3370
    Form Elements...
36

 

    Form Elements...
48
    Form Elements...
364
    Form Elements...
3374
    Form Elements...
335
    Form Elements...
3376

    Form Elements...
3293
    Form Elements...
343
    Form Elements...
3379
    Form Elements...
332

    Form Elements...
342
    Form Elements...
346
    Form Elements...
368
    Form Elements...
369

    Form Elements...
48
    Form Elements...
364
    Form Elements...
3387

    Form Elements...
3293
    Form Elements...
3389
    Form Elements...
320
    Form Elements...
332

    Form Elements...
342
    Form Elements...
346

    Form Elements...
342

    Form Elements...
342
    Form Elements...
3396

    Form Elements...
342
    Form Elements...
3398
    Form Elements...
320
    Form Elements...
332

    Form Elements...
342
    Form Elements...
21

    Form Elements...
326
    Form Elements...
3247

    Form Elements...
3249

 

    Form Elements...
3250

đầu ra. Nhập localhost/7058/chỉ mục. php trong trình duyệt của bạn, nó sẽ hiển thị dạng. Sau khi gửi biểu mẫu, dữ liệu biểu mẫu được gửi vào cơ sở dữ liệu

Hãy kiểm tra trong cơ sở dữ liệu của chúng tôi

PHP là ngôn ngữ kịch bản phía máy chủ được thiết kế dành riêng cho phát triển web. Bạn có thể học PHP từ đầu bằng cách làm theo Hướng dẫn PHP và Ví dụ về PHP này

PHP lưu trữ dữ liệu như thế nào?

Dữ liệu có thể được lưu trữ trong cookie mà trình duyệt của người dùng sẽ âm thầm lưu . Bạn có thể đọc dữ liệu trong một biến phiên, điều này sẽ cho phép chúng tôi xác định một người dùng cụ thể tại một thời điểm nhất định. Bạn có thể đọc dữ liệu được ghi trong tệp văn bản [txt, XML, v.v. ] hiện có trên máy chủ.

Làm cách nào để lưu trữ dữ liệu mà không cần cơ sở dữ liệu trong laravel?

Bạn có thể tạo bất kỳ cấu trúc dữ liệu nào tại đây mà bạn có thể cần. Bây giờ, khi bạn cần đọc một khóa từ dữ liệu này, bạn có thể sử dụng trình trợ giúp config[] của Laravel. $config = config['config_name. key'];

Có bắt buộc phải có cơ sở dữ liệu MySQL với PHP không?

Không . PHP là một ngôn ngữ lập trình. MySQL là một cơ sở dữ liệu.

Tôi có thể sử dụng PHP làm cơ sở dữ liệu không?

Với PHP, bạn có thể kết nối và thao tác với cơ sở dữ liệu . MySQL là hệ thống cơ sở dữ liệu phổ biến nhất được sử dụng với PHP.

Chủ Đề