Kamis, 27 Oktober 2022

MEMBUAT APK DARI DASAR

 PRAKTEK 1



membuat database di phpmyadmin, jangan lupa nyalakan XAMPP :






source code file "koneksi2.php"

<?php 

$host = mysqli_connect("localhost","root","","praktik281022");


function tambah($data){
global $host;

$nama = $_POST["nama"];

$tampil = mysqli_query($host, "INSERT INTO field (NAMA) VALUES ('$nama')");

return mysqli_affected_rows($host);
}

 ?>


source code file "input2.php"
<?php 
require 'koneksi2.php';

if (isset($_POST["submit"])) {
if (tambah($_POST)>0) {
echo "data berhasil ditambahkan";
header("location: index2.php");
}else{
echo "data gagal ditambahkan";
}
}
 ?>

 <!DOCTYPE html>
 <html>
 <head>
  <title></title>
 </head>
 <body>
  <form method="POST">
  <label>NAMA : </label>
  <input type="text" name="nama">
  <br>
  <input type="submit" name="submit" value="kirim">
  <input type="reset" value="reset">
  </form>
 </body>
 </html>


source code file "index2.php"
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h1>TAMPILAN DATA</h1>
<table border="1">
<tr>
<th>ID</th>
<th>NAMA</th>
</tr>

<?php 
include 'koneksi2.php';
$tampil = mysqli_query($host, "SELECT * FROM field order by ID desc limit 1");
foreach ($tampil as $data) {
?>
<tr>
<td><?php echo $data["ID"]; ?></td>
<td><?php echo $data["NAMA"]; ?></td>
</tr>
<?php } ?>

</table>
</body>
</html>


source code file "form2.php"
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php 
include 'koneksi2.php';
?>

<center>
<a href="index2.php">LIHAT SEMUA DATA</a>
</center>
<h1>DATA</h1>
<form action="input2.php" method="POST">
<table>
<tr>
<td>ID</td>
<td><input type="number" name="nomor"></td>
</tr>
<tr>
<td>NAMA</td>
<td><input type="name" name="nama"></td>
</tr>
</table>
</body>
</html>


HASIL TAMPILAN :




Tidak ada komentar:

Posting Komentar

Menambahkan Edit dan Delete pada PHP

 PRAKTIK 1 source code file "koneksi1.php" <?php  $host = mysqli_connect("localhost","root","",...