Membuat Formulir Pendaftaran Turnamen
HALO, kali ini mari kita membuat Formulir Pendaftaran Turnamen. Turnamen ini meliputi beberapa game fps, tetapi untuk form ini dibuat seolah tim-nya akan diacak dan ditentukan oleh panitia(pengurus)
Berikut Coding/Script-nya:
<!DOCTYPE html>
<html>
<head><title>Form Pendaftaran Tournament</title></head>
<body>
| PENDAFTARAN TOURNAMENT FPS PREMADE TEAMS |
<form method="Post">
<table border=0 width="75%"><tr>
<td width="20%">Nama Peserta</td>
<td><input type="text" name="Nama Peserta" Maxlength="25" size="25"></td></tr><tr>
<td width="20%">InGameName</td>
<td><input type="text" name="InGameName" Maxlength="25" size="25"></td></tr><tr>
<td width="20%">Nomor Telpon</td>
<td><input type="number" name="Nomor Telpon" Maxlength="13" size="12"></td></tr>
<td width="20%">Umur</td>
<td><input type="number" name="Umur" Maxlength="2" size="5">Tahun</td></tr><tr>
<td width="22%">Game
<select name="Game">
<option value="Valorant">Valorant
<option value="Rainbow 6 Siege">Rainbow 6 Siege
<option value="Apex Legends">Apex Legends
</td>
<td width="22%">Rank
<select name="Rank">
<option value="Bronze">Bronze
<option value="Silver">Silver
<option value="Gold">Gold
<option value="Platinum">Platinum
<option value="Diamond">Diamond
</td>
<td width="22%">Platform
<select name="Platform">
<option value="PS4">PS4
<option value="XBOX">XBOX
<option value="PC">PC
</td><tr>
</select>
<td width="20%">Jenis Kelamin</td>
<td><input type="radio" name="jenkel" Checked Value="Laki-Laki">Laki-Laki
<input type="radio" name="jenkel" Checked Value="Perempuan">Perempuan
</td></tr>
<td><input type="Submit" value="Submit">
<input type="reset" value="Cancel"></td>
</tr>
</form>
</body>
Berikut Hasilnya dan Cara mengisinya:
data.php
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<div style="overflow-x:auto; width: 100%;">
<!-- Search bar -->
<?php
require "koneksi.php";
$user = query("SELECT * FROM datapeserta, platform where datapeserta.id_platform= platform.id_platform ORDER BY id DESC");
error_reporting(0);
// Tombol cari ditekan
if(isset($_POST["cari"])) {
$user = cari($_POST["keyword"]);
$search = $_POST['keyword'];
} else {
}
?>
<br>
<center>
<div>
<div>
<form action="" method="post">
<input type="text" name="keyword" placeholder="Cari keyword" size="40"
autocomplete="off" autofocus>
<button type="submit" name="cari" ><i class="fa fa-search"></i></button>
</form>
</div>
<p>
<?php
if($search) {
echo "Anda mencari berdasarkan nama atau platform : $search";
} else {
echo "<p style='color: maroon;'>Peserta tidak ditemukan</p>";
}
?>
</p>
</center>
<!-- Search bar End -->
<!--awal table-->
<center><table class="center" border="5" cellpadding="10" cellspacing="0">
<!--awal header table-->
<tr class="center" align="center">
<th>No </th>
<!-- <th>ID Siswa</th> -->
<th>Nama</th>
<th>In Game Name</th>
<th>Jenis Kelamin</th>
<th>Game</th>
<th>Rank</td>
<th>Platform</th>
</tr>
<!--akhir header table-->
<?php echo $id['id'] ?>
<?php foreach( $user as $row ) : ?>
<!--awal menampilkan data dari tabel buku ke halaman web-->
<tr align="center">
<td> <?php echo $row['id'] ?></td>
<td> <?php echo $row['nama'] ?></td>
<td> <?php echo $row['ign']?></td>
<td> <?php echo $row['jenis_kel']?></td>
<td> <?php echo $row['game']?></td>
<td> <?php echo $row['rank']?></td>
<td> <?php echo $row['platform']?></td>
<td align="center">
</center>
<a href="index.php?page=edit&id=<?php echo $row['id'];?>">
</a>
<a href="delete.php?id=<?php echo $row['id'];?>" onclick="return confirm('Apa Anda yakin akan menghapus Data Akun?')">
Delete
</a>
</td>
</tr>
<?php $i++; ?>
<?php endforeach; ?>
<!--akhir menampilkan data dari tabel buku ke halaman web-->
</table>
<!--akhir table-->
</div>
delete.php
<?php
//koneksikan dengan database
include "koneksi.php";
//ambil idsiswa yang akan dihapus sebagai referensi
$idpeserta=$_GET['id'];
//query untuk menghapus data siswa
mysqli_query($sambung,"delete from datapeserta where id='$idsiswa'");
//arahkan ke halaman data siswa setelah menghapus 1 data siswa
echo "<script>
alert('Berhasil Dihapus, Peserta Berkurang!');
document.location.href = 'index.php?page=data';
</script>";
?>
edit.php
<?php
require "koneksi.php";
if(isset($_POST["submit"])) {
$id = $_POST['id'];
$nama = $_POST['nama'];
$jeniskel = $_POST['jenis_kel'];
$game = $_POST['game'];
$ign = $_POST['ign'];
$umur = $_POST['umur'];
$telp = $_POST['no_telp'];
$rank = $_POST['rank'];
$platform = $_POST['platform'];
$sql = mysqli_query ($koneksi, "UPDATE datapeserta SET nama = '$nama', ign = '$ign', no_telp = '$telp', umur = '$umur', game = '$game', rank = '$rank', id_platform = '$platform' ,jenis_kel = '$jeniskel' WHERE id = '$id' ");
echo "<script>
alert('Data berhasil diubah!');
document.location.href = 'index.php?page=data';
</script>";
}
$id = $_GET['id'];
$query_tampil = mysqli_query ($koneksi, "SELECT * FROM datapeserta WHERE id = '$id' ");
$edit = mysqli_fetch_array($query_tampil);
$query = mysqli_query($koneksi, "SELECT * FROM datapeserta ORDER BY id DESC");
?>
<?php
if (isset($_POST['submit'])) {
if (edit($_POST)>0){
} else {
echo "<script>
alert('Data gagal diubah!');
document.location.href = 'index.php?page=data';
</script>";
return false;
}
}
$id = $_GET['id'];
$ambildata = mysqli_query($koneksi, "select * from datapeserta where id = $id");
while ($tampildata = mysqli_fetch_array($ambildata)) {
?>
<h1 style="color: #212121">
<center>📝 EDIT PENDAFTARAN 📝</center>
</h1>
<hr>
<div class="container" style="margin-top: -5px;">
<form action="" method="post" enctype="multipart/form-data">
<div class="row">
<div class="col-25">
<label for="fname">ID Peserta</label>
</div>
<div class="col-75">
<input type="text" name="id" value="<?php echo $tampildata['id'] ?>" readonly>
</div>
</div>
<hr>
<div class="row">
<div class="col-25">
<label for="lname">Nama</label>
</div>
<div class="col-75">
<input type="text" name="nama" value="<?php echo $tampildata['nama'] ?>" autocomplete="off">
</div>
</div>
<hr>
<input type="hidden" name="id" value="<?php echo $tampildata["id"]?>"/>
<div class="row">
<div class="col-25">
<label for="lname">Jenis Kelamin</label>
</div>
<div class="col-75">
<div class="wrapper">
<input type="radio" name="jenis_kel" value="Pria" id="option-1" <?php
if($tampildata["jenis_kel"]=='Pria'){
echo "checked";
}
?>/>Pria
<input type="radio" name="jenis_kel" value="Wanita" id="option-2" <?php
if($tampildata["jenis_kel"]=='Wanita'){
echo "checked";
}
?>/>Wanita
<label for="option-1" class="option option-1">
<div class="dot"></div>
<!-- <span>Pria</span> -->
</label>
<label for="option-2" class="option option-2">
<div class="dot"></div>
<!-- <span>Wanita</span> -->
</label>
</div>
</div>
<hr>
<div class="row">
<div class="col-25">
<label for="tipe">Platform</label>
</div>
<div class="col-75">
<select name="platform" id="tipe" required>
<option value="<?php echo $tampildata['id_platform'] ?>"></option>
<option value="1">PC</option>
<option value="2">PS4</option>
<option value="3">XBOX</option>
</select>
</div>
<hr>
<div>
<table border=0 width="75%"><tr>
<td width="20%">InGameName</td>
<td><input type="text" name="ign" value="<?php echo $tampildata['ign'] ?>" Maxlength="25" size="25"></td></tr><tr>
<td width="20%">Nomor Telpon</td>
<td><input type="number" name="no_telp" value="<?php echo $tampildata['no_telp'] ?>" Maxlength="13" size="12"></td></tr>
<td width="20%">Umur</td>
<td><input type="number" name="umur" value="<?php echo $tampildata['umur'] ?>" Maxlength="2" size="5">Tahun</td></tr><tr>
<td width="22%">Game
<select name="game">
<option value="Rainbow 6 Siege">Rainbow 6 Siege
<option value="Apex Legends">Apex Legends
</td>
<td width="22%">Rank
<select name="rank">
<option value="Bronze">Bronze
<option value="Silver">Silver
<option value="Gold">Gold
<option value="Platinum">Platinum
<option value="Diamond">Diamond
</td>
</td><tr>
</select>
</tr>
</div>
<script>
function showPreview(event){
if(event.target.files.length > 0){
var src = URL.createObjectURL(event.target.files[0]);
var preview = document.getElementById("file-ip-1-preview");
preview.src = src;
preview.style.display = "block";
}
}
</script>
<div style="margin-top: 10px;">
<input type="submit" name="submit" value="Edit" onclick="return confirm('Apa Anda yakin akan mengubah data?')">
<button type="button" onclick="location.reload();">Reset</button>
</div>
</form>
</div>
<?php
}
?>
index.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins&family=Silkscreen&display=swap" rel="stylesheet">
<title>Turnamen Gim R6 & APEX</title>
</head>
<body>
<div>
<center>
<h1>List Peserta Tournament Tembak-Menembak</h1>
<a href="index.php?page=data">List
</a>
<>
<a href="index.php?page=tambah">Daftar</a>
</center>
</div>
<div style="height: 100%; width: 100%;">
<?php
if (isset($_GET['page'])) {
$page = $_GET['page'];
switch ($page) {
case 'data':
include "data.php";
break;
case 'edit':
include "edit.php";
break;
case 'tambah':
include "tambah.php";
break;
case 'cari':
include "cari.php";
break;
default:
echo "<h1 style='padding: 20%; color: red;'>😫 Maaf halaman yang anda tuju tidak ada</h1>";
break;
}
}
?>
</div>
</body>
</html>
tambah.php
<?php
require 'koneksi.php';
if (isset($_POST['submit'])) {
if (tambah($_POST)>0){
echo "<script>
alert('Pendaftaran Sukses, kamu sudah jadi peserta!');
document.location.href = 'index.php?page=data';
</script>";
}else{
echo "<script>
alert('Gagal Mendaftar, pastikan sudah mengisi dengan benar!');
document.location.href = 'index.php?page=data';
</script>";
}
}
?>
<h1 style="color: cyan">
<center>DAFTAR</center>
</h1>
<center>
<form method="Post">
<table border=0 width="75%"><tr>
<td width="20%">Nama Peserta</td>
<td><input type="text" name="nama" Maxlength="25" size="25"></td></tr><tr>
<td width="20%">InGameName</td>
<td><input type="text" name="ign" Maxlength="25" size="25"></td></tr><tr>
<td width="20%">Nomor Telpon</td>
<td><input type="number" name="no_telp" Maxlength="13" size="12"></td></tr>
<td width="20%">Umur</td>
<td><input type="number" name="umur" Maxlength="2" size="5">Tahun</td></tr><tr>
<td width="22%">Game
<select name="game">
<option value="Rainbow 6 Siege">Rainbow 6 Siege
<option value="Apex Legends">Apex Legends
</td>
<td width="22%">Rank
<select name="rank">
<option value="Bronze">Bronze
<option value="Silver">Silver
<option value="Gold">Gold
<option value="Platinum">Platinum
<option value="Diamond">Diamond
</td>
<td width="22%">Platform
<select name="platform">
<option value="1">PC
<option value="2">PS4
<option value="3">XBOX
</td><tr>
</select>
<td width="20%">Jenis Kelamin</td>
<td><input type="radio" name="jenis_kel" Checked Value="Laki-Laki">Laki-Laki
<input type="radio" name="jenis_kel" Checked Value="Perempuan">Perempuan
</td></tr>
<td><input type="submit" name="submit" class="btn btn-tambah">
<button type="reset" name="reset" onclick="location.reload();">Reset</button>
<input type="reset" value="Cancel"></td>
</tr>
</form>
</center>
<hr>
</div>
</form>
</div>
koneksi.php
<?php
//koneksi ke database melalui koneksi.php
$host = "localhost";
$user = "root";
$password = "";
$dbname = "tourneuy";
$sambung=mysqli_connect($host,$user,$password,$dbname);
$koneksi = mysqli_connect("localhost","root","","tourneuy") ;
function query($query){
global $koneksi;
$result = mysqli_query($koneksi, $query);
$rows = [];
while( $row = mysqli_fetch_assoc($result)) {
$rows[] = $row;
}
return $rows;
}
function tambah(){
global $koneksi;
$nama = $_POST['nama'];
$jeniskel = $_POST['jenis_kel'];
$game = $_POST['game'];
$ign = $_POST['ign'];
$umur = $_POST['umur'];
$telp = $_POST['no_telp'];
$rank = $_POST['rank'];
$platform = $_POST['platform'];
$value = implode(",", $platform);
$sql = "INSERT INTO datapeserta (nama,ign,no_telp,umur,game,rank,id_platform,jenis_kel) VALUES ('$nama','$ign','$telp','$umur','$game','$rank','$platform','$jeniskel')
";
// $sql = "INSERT INTO tb_user VALUES
// nama='$nama',
// jenis_kel='$jeniskel',
// kelas='$kelas',
// hobi='$value',
// gambar='$gambar'
// ";
mysqli_query($koneksi, $sql);
return mysqli_affected_rows($koneksi);
}
function edit() {
global $koneksi;
$id = $_GET['id'];
$nama = $_POST['nama'];
$jeniskel = $_POST['jenis_kel'];
$game = $_POST['game'];
$ign = $_POST['ign'];
$umur = $_POST['umur'];
$telp = $_POST['no_telp'];
$rank = $_POST['rank'];
$platform = $_POST['platform'];
$value = implode(",", $platform);
// $sql = "UPDATE tb_user 'nama','jenis_kel','kelas','hobi','gambar' SET ('$nama''$jeniskel''$kelas''$value''$gambar') WHERE id = $id";
$sql = "UPDATE datapeserta SET
nama='$nama',
ign='$ign',
no_telp ='$telp',
umur = '$umur',
game = '$game'
rank = '$rank',
id_platform='$platform',
jenis_kel='$jeniskel'
WHERE id = $id";
mysqli_query($koneksi, $sql);
return mysqli_affected_rows($koneksi);
}
function cari($keyword) {
$query =("SELECT * FROM datapeserta, platform where datapeserta.id_platform= platform.id_platform and nama like '%$keyword%' or datapeserta.id_platform= platform.id_platform and platform like '%$keyword%' ORDER BY id DESC");
return query($query);
}
?>
Terimakasih telah mengunjungi Artikel ini, semoga bermanfaat untuk kita semua.
Comments
Post a Comment