By GokiSoft.com|
20:07 23/02/2022|
Học PHP
[Video] Form đăng ký tài khoản người dùng - Registation Form trong PHP - C2108L
Form đăng ký tài khoản người dùng - Registation Form trong PHP - Lập trình PHP - Lập Trình PHP MySQL
#input.php
<?php
// var_dump($_POST);
// var_dump($_GET);
// $_GET = [] -> empty($_GET) -> true
// isset($_GET['a']) -> false
// isset($_GET['c']) -> false
// $_GET = ["a"=>"asdasgh", "b" => "adsadsad"] -> empty($_GET) -> false
// isset($_GET['a']) -> true
// isset($_GET['c']) -> false
// Kiem tra xem co du lieu day tu form method: post -> len hay khong
$username = $email = $pwd = "";
if(!empty($_GET)) {
// Khai bao nhanh 3 bien cung nhan gia tri empty
if(isset($_GET['uname'])) {
$username = $_GET['uname'];
}
if(isset($_GET['email'])) {
$email = $_GET['email'];
}
if(isset($_GET['password'])) {
$pwd = $_GET['password'];
}
}
if(!empty($_POST)) {
// Khai bao nhanh 3 bien cung nhan gia tri empty
if(isset($_POST['username'])) {
$username = $_POST['username'];
}
if(isset($_POST['email'])) {
$email = $_POST['email'];
}
if(isset($_POST['pwd'])) {
$pwd = $_POST['pwd'];
}
if($username == "dieptv" && $pwd == "123") {
//Chuyen sang trang welcome.php
header("Location: welcome.php?uname=$username&email=$email&password=$pwd");
die(); //Ngung tra du lieu ve client
}
}
// username, email, pwd -> lay dc thong tin tu form gui len.
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Register Form</title>
<!-- Bootstrap -> thiet ke GUI -->
<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: 15px;
}
</style>
</head>
<body>
<div class="container">
<div class="card">
<div class="card-header bg-info text-white">
Nhap Thong Tin Tai Khoan
</div>
<div class="card-body">
<form method="post">
<div class="form-group">
<label>Tai Khoan: </label>
<input type="text" name="username" class="form-control" placeholder="Nhap ten tai khoan" value="<?=$username?>">
</div>
<div class="form-group">
<label>Email: </label>
<input type="email" name="email" class="form-control" placeholder="Nhap email" value="<?=$email?>">
</div>
<div class="form-group">
<label>Mat Khau: </label>
<input type="password" name="pwd" class="form-control" placeholder="Nhap mat khau" value="<?=$pwd?>">
</div>
<div class="form-group">
<button class="btn btn-success">Dang Ky</button>
<button class="btn btn-warning">Xoa Form</button>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
#welcome.php
<?php
// var_dump($_POST);
// var_dump($_GET);
// http://localhost:82/c2108l/bt1615/welcome.php?uname=dieptv&email=tranvandiep.it@gmail.com&password=123
// URL -> chua du lieu uname, email, passowrd -> GET
$uname = $email = $password = "";
if(!empty($_GET)) {
if(isset($_GET['uname'])) {
$uname = $_GET['uname'];
}
if(isset($_GET['email'])) {
$email = $_GET['email'];
}
if(isset($_GET['password'])) {
$password = $_GET['password'];
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Welcome Page</title>
<!-- Bootstrap -> thiet ke GUI -->
<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: 15px;
}
</style>
</head>
<body>
<div class="container">
<table class="table table-bordered">
<tr>
<th style="width: 200px">Ten Tai Khoan: </th>
<td><?php echo $uname; ?></td>
</tr>
<tr>
<th>Email: </th>
<td><?=$email?></td>
</tr>
<tr>
<th>Mat Khau: </th>
<td>
<?=$password?>
<!-- Build URL -> gui du lieu sang trang input.php bang giao thu GET -->
<!-- POST & GET -->
<a href="input.php?uname=<?=$uname?>&email=<?=$email?>&password=<?=$password?>">
<button class="btn btn-warning btn-sm">Edit</button>
</a>
</td>
</tr>
</table>
</div>
</body>
</html>
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)
![GokiSoft.com [Teacher]](https://www.gravatar.com/avatar/fc6ba9324e017d540af3613b3a77dd21.jpg?s=80&d=mm&r=g)
GokiSoft.com
2022-02-23 14:27:30
<?php
$s = $a = $b = $cal = "";
if(!empty($_GET)) {
if(isset($_GET['a'])) {
$a = $_GET['a'];
}
if(isset($_GET['b'])) {
$b = $_GET['b'];
}
if(isset($_GET['cal'])) {
$cal = $_GET['cal'];
}
switch ($cal) {
case '+':
$s = $a + $b;
break;
case '-':
break;
}
}
if($s != '') {
$s = $a.$cal.$b.'='.$s;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Calculator Online</title>
<!-- Bootstrap -> thiet ke GUI -->
<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>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<style type="text/css">
.form-group {
margin-bottom: 15px;
}
</style>
</head>
<body>
<div class="container">
<form method="get" id="MyForm">
<input type="text" name="a" class="form-control" placeholder="Enter a" style="display: none;">
<input type="text" name="cal" class="form-control" placeholder="Enter calculator" style="display: none;">
<input type="text" name="b" class="form-control" placeholder="Enter b" style="display: none;">
<button style="display: none;">Submit</button>
</form>
<input type="text" value="<?=$s?>">
<br/>
<!-- Xay du giao dien Calculator -->
<input type="button"value="1">
<input type="button"value="2">
<input type="button"value="3">
<input type="button"value="4">
<input type="button"value="5">
<input type="button"value="6">
<input type="button"value="7">
<input type="button"value="8">
<input type="button"value="9">
<input type="button"value=".">
<br/>
<input type="button"value="+">
<input type="button"value="-">
<input type="button"value="*">
<input type="button"value="/">
<input type="button"value="%">
<br/>
<input type="button" value="=" onclick="submitForm()">
</div>
<script type="text/javascript">
function submitForm() {
$('#MyForm').submit() //Gui du lieu len server
}
</script>
</body>
</html>