By GokiSoft.com| 14:02 20/04/2022|
Học PHP

[Source Code] Quản lý sinh viên bằng Session - Khóa học PHP/MySQL - C2110I

Quản lý sinh viên bằng Session - Khóa học PHP/MySQL


#index.php


<?php
session_start();

// include_once
require_once('process_form.php');
// require('process_form.php');
// require('process_form.php');
// require('process_form.php');
// require('process_form.php');
// require('process_form.php');
// require('process_form.php');
?>

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Quan Ly Sinh Vien</title>
	<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
	<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>

	<style type="text/css">
		.form-group {
			margin-bottom: 20px;
		}

		.card {
			margin-bottom: 20px;
		}
	</style>
</head>
<body>
<div class="container">
	<div class="card">
		<div class="card-header bg-info text-white">
			Danh Sach Sinh Vien
		</div>
		<div class="card-body">
			<table class="table table-bordered">
				<thead>
					<tr>
						<th>No</th>
						<th>Full Name</th>
						<th>Email</th>
						<th>Password</th>
					</tr>
				</thead>
				<tbody>
<?php
$index = 0;
foreach ($studentList as $item) {
	echo '<tr>
			<td>'.($index + 1).'</td>
			<td>'.$item['fullname'].'</td>
			<td>'.$item['email'].'</td>
			<td>'.$item['pwd'].'</td>
		</tr>';
	$index++;
}
?>
				</tbody>
			</table>
		</div>
	</div>

	<div class="card">
		<div class="card-header bg-info text-white">
			Nhap Thong Tin Sinh Vien
		</div>
		<div class="card-body">
			<form method="post">
				<div class="form-group">
					<label>Full Name: </label>
					<input type="text" name="fullname" class="form-control">
				</div>
				<div class="form-group">
					<label>Email: </label>
					<input type="email" name="email" class="form-control">
				</div>
				<div class="form-group">
					<label>Password: </label>
					<input type="password" name="pwd" class="form-control">
				</div>
				<div class="form-group">
					<button class="btn btn-info">Register</button>
				</div>
			</form>
		</div>
	</div>
</div>
</body>
</html>


#process_form.php


<?php
// echo '<h1>asdas</h1>';
$fullname = $email = $pwd = "";

if(!isset($_SESSION['studentList'])) {
	$_SESSION['studentList'] = [];
}

//Phan 1: Lay dc du lieu gui tu client len server
if(!empty($_POST)) {
	if(isset($_POST['fullname'])) {
		$fullname = $_POST['fullname'];
	}
	if(isset($_POST['email'])) {
		$email = $_POST['email'];
	}
	if(isset($_POST['pwd'])) {
		$pwd = $_POST['pwd'];
	}

	// Phan 3:
	$std = [
		'fullname' => $fullname,
		'email' => $email,
		'pwd' => $pwd
	];
	$_SESSION['studentList'][] = $std;
}

// Phan 2: Hien thi danh sach sinh vien bang PHP
$studentList = $_SESSION['studentList'];


Tags:



Phản hồi từ học viên

5

(Dựa trên đánh giá ngày hôm nay)

Đăng nhập để làm bài kiểm tra

Chưa có kết quả nào trước đó