By GokiSoft.com|
18:38 21/05/2022|
Học PHP
[Examination] Thi kết thúc khóa học PHP - Đề 1
Đề Thi Môn PHP
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)
![Nguyễn Anh Vũ [T2008A]](https://www.gravatar.com/avatar/8863d24ed74b396082becbc4db8331fd.jpg?s=80&d=mm&r=g)
Nguyễn Anh Vũ
2021-06-30 09:37:00
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/library/index', [App\Http\Controllers\Library\LibraryController::class, 'index'])->name('library_index');
![Đỗ Minh Quân [T2008A]](https://www.gravatar.com/avatar/fa40264d7c4b4209c87a9e9451d2b9f0.jpg?s=80&d=mm&r=g)
Đỗ Minh Quân
2021-06-30 09:35:33
<?php
require_once ('dbhelper.php');
$authorid = $title = $isbn = $pub_year = $available = '';
if(!empty($_POST)) {
$id = '';
if (isset($_POST['authorid'])) {
// code...
$authorid = $_POST['authorid'];
}
if (isset($_POST['title'])) {
// code...
$title = $_POST['title'];
}
if (isset($_POST['isbn'])) {
// code...
$isbn = $_POST['isbn'];
}
if (isset($_POST['pub_year'])) {
// code...
$pub_year = $_POST['pub_year'];
}
if (isset($_POST['available'])) {
// code...
$available = $_POST['available'];
}
if (isset($_POST['id'])) {
// code...
$id = $_POST['id'];
}
$authorid =str_replace('\'', '\\\'', $authorid);
$title =str_replace('\'', '\\\'', $title);
$isbn =str_replace('\'', '\\\'', $isbn);
$pub_year =str_replace('\'', '\\\'', $pub_year);
$available =str_replace('\'', '\\\'', $available);
if($id != '') {
$sql =
"update book set where id =".$id;
} else {
$spl = "insert into book(authorid, title, isbn, pub_year, available) values ('$authorid', '$title', '$isbn', '$pub_year', '$available')";
}
execute($sql);
header('Location: Book.php');
<!DOCTYPE html>
<html>
<head>
<title>Add Book</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">Input Book</h2>
</div>
<div class="panel-body">
<form method="post">
<div class="form-group">
<label for="usr">Authorid:</label>
<input type="name" name="id" value="<?=$id?>" style="display: none;">
<input required="true" type="number" class="form-control" id="authorid" name="authorid" >
</div>
<div class="form-group">
<label for="usr">Title:</label>
<input required="true" type="text" class="form-control" id="title" name="title" >
</div>
<div class="form-group">
<label for="address">ISBN:</label>
<input type="text" class="form-control" id="isbn" name="isbn" >
</div>
<div class="form-group">
<label for="address">Pub_year:</label>
<input type="text" class="form-control" id="pub_year" name="pubyear" >
</div>
<div class="form-group">
<label for="address">Available:</label>
<input type="text" class="form-control" id="available" name="available">
</div>
<a href="Book.php"><button type="button" class="btn btn-danger">BookList</button></a>
<button class="btn btn-success">Save</button>
</form>
</div>
</div>
</div>
</body>
</html>
![Đỗ Minh Quân [T2008A]](https://www.gravatar.com/avatar/fa40264d7c4b4209c87a9e9451d2b9f0.jpg?s=80&d=mm&r=g)
Đỗ Minh Quân
2021-06-30 09:34:22
<?php
require_once ('config.php');
function execute($sql) {
$conn = mysqli_connect(host, username, password, database);
mysqli_set_charset($conn, 'utf8');
mysqli_query($conn, $sql);
mysqli_close($conn);
}
// insert datebase
function executeResult($sql) {
$conn = mysqli_connect(host, username, password, database);
mysqli_set_charset($conn, 'utf8');
$data= [];
$resultset = mysqli_query($conn, $sql);
while (($row = mysqli_fetch_array($resultset, 1)) != null) {
$data[] = $row;
}
mysqli_close($conn);
}
function removeSpecialCharacter($str) {
$str = str_replace('\\', '\\\\', $str);
$str = str_replace('\'', '\\\'', $str);
}
function getPOST($key) {
$value = '';
if (isset($_POST[$key])) {
$value = $_POST[$key];
}
return removeSpecialCharacter($value);
}
![Trần Văn Lâm [T2008A]](https://www.gravatar.com/avatar/cfc15c8cb7781ad669b013e01f9f1a6b.jpg?s=80&d=mm&r=g)
Trần Văn Lâm
2021-06-30 09:34:19
#LibraryController.php
<?php
namespace App\Http\Controllers\Library;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class LibraryController extends Controller
{
public function index(Request $request){
$bookList = DB::table('libary')->get();
return view('library.index')->with([
'bookList' => $bookList
]);
}
}
#index.blade.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Page</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="row">
<table class="table table-bordered">
<thead>
<th>bookid</th>
<th>authorid</th>
<th>Title</th>
<th>ISBN</th>
<th>pub_year</th>
<th>available</th>
</thead>
<tbody>
@foreach($bookList as $item)
<tr>
<td>{{ $item->bookid }}</td>
<td>{{ $item->authorid }}</td>
<td>{{ $item->title }}</td>
<td>{{ $item->ISBN }}</td>
<td>{{ $item->pub_year }}</td>
<td>{{ $item->available }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</body>
</html>
#LibrarySeeder.php
<?php
namespace Database\Seeders;
use DB;
use Illuminate\Database\Seeder;
class LibrarySeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
for($i = 0; $i < 11; $i++){
DB::table('library')->insert([
'bookid' => 'Ma sach'.$i,
'authorid' => 'Ma tac gia'.$i,
'title' => 'Tieu De '.$i,
'ISBN' => '970-999-999',
'pub_year' => '2010'.$i,
'available' => '10'.$i
]);
}
}
}
#2021_06_30_083623_create_library_table.php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateLibraryTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('library', function (Blueprint $table) {
$table->integer('bookid');
$table->primary('bookid');
$table->integer('authorid');
$table->string('title', 55);
$table->string('ISBN', 25);
$table->smallInteger('pub_year');
$$table->tinyInteger('available');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('library');
}
}
#library.php
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/library/index', [App\Http\Controllers\Library\LibraryController::class, 'index'])->name('library_index');
![Nguyễn đình quân [T2008A]](https://www.gravatar.com/avatar/46aca6afcfe99fdb28357afb847d8a0c.jpg?s=80&d=mm&r=g)
Nguyễn đình quân
2021-06-30 09:31:49
<?php
namespace App\Http\Controllers\Library;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class LibraryController extends Controller
{
public function showBook(Request $request)
{
$s = $request->s;
$bookList = DB::table('library');
if(isset($s) && $s > 0){
$bookList = $bookList->where('library.title','like','%'.$s.'%');
}
$bookList = $bookList->get();
return view('library.index')->with([
'bookList' => $bookList,
'index' => 1
]);
}
}
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class LibrarySeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
for ($i=1; $i <= 10; $i++) {
DB::table('library')->insert([
'authorid' => $i,
'title' => 'Quyen sach ' . $i,
'ISBN' => '123' . $i,
'pub_year' => '200'.$i,
'available' => $i + 20
]);
}
}
}
Aa
<!doctype html>
<html lang="en">
<head>
<title>Exam</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="{{ asset('css/library.css') }}">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<div class="container">
<h1>Exam</h1>
<form method="get">
<div class="form-group">
<input type="text" class="form-control" name="search" placeholder="Searching for title...">
</div>
</form>
<table class="table table-bordered">
<thead>
<tr>
<th>No</th>
<th>Title</th>
<th>ISBN</th>
<th>Publish Year</th>
<th>Available</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
@foreach ($bookList as $book)
<tr>
<td>{{$index++}}</td>
<td>{{$book -> title}}</td>
<td>{{$book -> ISBN}}</td>
<td>{{$book -> pub_year}}</td>
<td>{{$book -> available}}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</body>
</html>
<!doctype html>
<html lang="en">
<head>
<title>Exam</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="{{ asset('css/library.css') }}">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<div class="container">
<h1>Exam</h1>
<form method="get">
<div class="form-group">
<input type="text" class="form-control" name="search" placeholder="Searching for title...">
</div>
</form>
<table class="table table-bordered">
<thead>
<tr>
<th>No</th>
<th>Title</th>
<th>ISBN</th>
<th>Publish Year</th>
<th>Available</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
@foreach ($bookList as $book)
<tr>
<td>{{$index++}}</td>
<td>{{$book -> title}}</td>
<td>{{$book -> ISBN}}</td>
<td>{{$book -> pub_year}}</td>
<td>{{$book -> available}}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</body>
</html>
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class LibrarySeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
for ($i=1; $i <= 5; $i++) {
DB::table('exam')->insert([
'authorid' => $i,
'title' => 'zzzzzz' . $i,
'ISBN' => '1' . $i,
'pub_year' => '1'.$i,
'available' => $i + 10
]);
}
}
}
![Đỗ Minh Quân [T2008A]](https://www.gravatar.com/avatar/fa40264d7c4b4209c87a9e9451d2b9f0.jpg?s=80&d=mm&r=g)
Đỗ Minh Quân
2021-06-30 09:28:58
<?php
require_once ('dbhelper.php');
$book = executeResult('select * from book');
?>
<!DOCTYPE html>
<html>
<head>
<title>Book</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">Books</h2>
</div>
<div class="panel-body">
<a href="addBook.php"><button class="btn btn-success" style="margin-bottom: 15px">Add Book</button></a>
<input type="text" name="input" size="50" style="margin-left: 500px">
<table class="table table-bordered">
<thead>
<tr>
<th>Bookid</th>
<th>Authorid</th>
<th>Title</th>
<th>ISBN</th>
<th>pub_year</th>
<th>Available</th>
</tr>
</thead>
<tbody>
<?php
$count = 0;
foreach ($list_library as $library) {
# code...
echo '<tr>
<td>'.($count++).'</td>
<td>'['authorid'].'</td>
<td>'['title'].'</td>
<td>'['isbn'].'</td>
<td>'['pub_year'].'</td>
<td>'['available'].'</td>
<td><button class="btn btn-warning" onclick=\'window.open("addstudent.php?id='.$std['id'].'", "_self")\'>Edit</button></td>
<td><button class="btn btn-danger" onclick="deleteStudent('.$std['id'].')">Delete</button></td>
</tr>';
}
?>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
![Vũ Đình Khôi [community,T2008A]](https://www.gravatar.com/avatar/522a3ab049e7409705e97b96dbbc327b.jpg?s=80&d=mm&r=g)
Vũ Đình Khôi
2021-06-30 09:28:32
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class LibrarySeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
for ($i=1; $i <= 10; $i++) {
DB::table('library')->insert([
'authorid' => $i,
'title' => 'Quyen sach ' . $i,
'ISBN' => '123' . $i,
'pub_year' => '200'.$i,
'available' => $i + 20
]);
}
}
}
<?php
namespace App\Http\Controllers\Library;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class LibraryController extends Controller
{
public function showBook(Request $request)
{
$s = $request->s;
$bookList = DB::table('library');
if(isset($s) && $s > 0){
$bookList = $bookList->where('library.title','like','%'.$s.'%');
}
$bookList = $bookList->get();
return view('library.index')->with([
'bookList' => $bookList,
'index' => 1
]);
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Book List</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<style>
body{
background-color: red !important;
}
h1{
text-align: center;
color: blue;
}
input{
width: 180px !important;
}
</style>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<div class="container">
<h1>Book list</h1>
<form method="get">
<div class="form-group">
<input type="text" class="form-control" name="search">
</div>
</form>
<table class="table table-bordered">
<thead>
<tr>
<th>No</th>
<th>Title</th>
<th>ISBN</th>
<th>Publish Year</th>
<th>Available</th>
</tr>
</thead>
<tbody>
@foreach ($bookList as $item)
<tr>
<td>{{$index++}}</td>
<td>{{$item -> title}}</td>
<td>{{$item -> ISBN}}</td>
<td>{{$item -> pub_year}}</td>
<td>{{$item -> available}}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</body>
</html>
![Đức Sơn [T2008A]](https://www.gravatar.com/avatar/d2b971b7bc54e4a9689c3e2240f27949.jpg?s=80&d=mm&r=g)
Đức Sơn
2021-06-30 09:27:11
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateLibraryTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('library', function (Blueprint $table) {
$table->id('bookid');
$table->integer('authorid');
$table->string('title');
$table->string('ISBN');
$table->integer('pub_year');
$table->integer('available');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('library');
}
}
![Đức Sơn [T2008A]](https://www.gravatar.com/avatar/d2b971b7bc54e4a9689c3e2240f27949.jpg?s=80&d=mm&r=g)
Đức Sơn
2021-06-30 09:26:40
<?php
namespace App\Http\Controllers\Library;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class LibraryController extends Controller
{
public function showBook(Request $request)
{
$s = $request->s;
$bookList = DB::table('library');
if(isset($s) && $s > 0){
$bookList = $bookList->where('library.title','like','%'.$s.'%');
}
$bookList = $bookList->get();
return view('library.index')->with([
'bookList' => $bookList,
'index' => 1
]);
}
}
![Đức Sơn [T2008A]](https://www.gravatar.com/avatar/d2b971b7bc54e4a9689c3e2240f27949.jpg?s=80&d=mm&r=g)
Đức Sơn
2021-06-30 09:26:19
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class LibrarySeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
for ($i=1; $i <= 10; $i++) {
DB::table('library')->insert([
'authorid' => $i,
'title' => 'Quyen sach ' . $i,
'ISBN' => '123' . $i,
'pub_year' => '200'.$i,
'available' => $i + 20
]);
}
}
}