By GokiSoft.com|
19:40 21/11/2022|
Học PHP
[Source Code] Tìm hiểu GET & POST trong PHP - C2206L
#form.php
<?php
// var_dump($_GET);
// var_dump($_POST);
$fullname = $email = $birthday = $address = "";
if(!empty($_POST)) {
$fullname = $_POST['fullname'];
$email = $_POST['email'];
$birthday = $_POST['birthday'];
$address = $_POST['address'];
echo $fullname;
if($fullname == 'admin') {
// header("Location: test.php?fname=$fullname&add=$address");
header("Location: show.php?fullname=$fullname&address=$address&birthday=$birthday&email=$email");
die();
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Registation Form * Form Tutorial</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<!-- Popper JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="panel panel-primary">
<div class="panel-heading">
<h2 class="text-center">Registation Form - Input User's Detail Information</h2>
</div>
<div class="panel-body">
<form method="post">
<div class="form-group">
<label for="usr">Name:</label>
<input required="true" type="text" class="form-control" id="usr" name="fullname" value="<?=$fullname?>">
</div>
<div class="form-group">
<label for="email">Email:</label>
<input required="true" type="email" class="form-control" id="email" name="email" value="<?=$email?>">
</div>
<div class="form-group">
<label for="birthday">Birthday:</label>
<input type="date" class="form-control" id="birthday" name="birthday" value="<?=$birthday?>">
</div>
<div class="form-group">
<label for="address">Address:</label>
<input type="text" class="form-control" id="address" name="address" value="<?=$address?>">
</div>
<button type="submit" class="btn btn-success">Register</button>
</form>
</div>
</div>
</div>
</body>
</html>
#form2.php
<!DOCTYPE html>
<html>
<head>
<title>Registation Form * Form Tutorial</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<!-- Popper JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="panel panel-primary">
<div class="panel-heading">
<h2 class="text-center">Registation Form - Input User's Detail Information</h2>
</div>
<div class="panel-body">
<form method="post" action="show.php">
<div class="form-group">
<label for="usr">Name:</label>
<input required="true" type="text" class="form-control" id="usr" name="fullname">
</div>
<div class="form-group">
<label for="email">Email:</label>
<input required="true" type="email" class="form-control" id="email" name="email">
</div>
<div class="form-group">
<label for="birthday">Birthday:</label>
<input type="date" class="form-control" id="birthday" name="birthday">
</div>
<div class="form-group">
<label for="address">Address:</label>
<input type="text" class="form-control" id="address" name="address">
</div>
<button type="submit" class="btn btn-success">Register</button>
</form>
</div>
</div>
</div>
</body>
</html>
#readme.txt
u뚀
#show.php
<?php
$fullname = $email = $birthday = $address = "";
if(!empty($_GET)) {
$fullname = $_GET['fullname'];
$email = $_GET['email'];
$birthday = $_GET['birthday'];
$address = $_GET['address'];
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Registation Form * Form Tutorial</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<!-- Popper JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="panel panel-primary">
<div class="panel-heading">
<h2 class="text-center">Show Data</h2>
</div>
<div class="panel-body">
<table class="table table-bordered">
<thead>
<tr>
<th>Full Name</th>
<th>Email</th>
<th>Birthday</th>
<th>Address</th>
</tr>
</thead>
<tbody>
<tr>
<td><?=$fullname?></td>
<td><?=$email?></td>
<td><?=$birthday?></td>
<td><?=$address?></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
#test.php
<?php
var_dump($_GET);
// echo $_GET['fullname'];
echo $_GET['fname'];
#vidu.php
<?php
if(!empty($_GET)) {
//Nghia la gi?
// echo $_GET['title'];
header('Location: test.php?x=1&y=2');
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>GET tutorial</title>
</head>
<body>
<form method="get">
<input type="text" name="title" size="50">
<button>Submit Data</button>
</form>
</body>
</html>
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)