Part 2

KONEKSINYA

<?php

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

        if($host){  

            echo "koneksi host berhasil.<br>";

        }else{

            echo "koneksi host gagal.<br>";

        }


    $db = mysqli_select_db ($host, "pt2");

        if($db){

            echo "koneksi ke DB berhasil.<br>";

        }else{

            echo "koneksi ke DB gagal.<br>";

        }

?>

FORMULIRNYA

<!DOCTYPE html>

<html>

<head>

<title>Undangan</title>

</head>

<body>

<form method="post" action="tampilan.php">

<label>Nama : </label><input type="text" name="nama"><br>

<label>Kelas :</label> <input type="tex" name="kelas"> <br>

<input type="submit" value=kirim><br>

<input type="reset" name="reset">

</form>

</body>

</html>

TAMPILANNYA

 <?php 

include "konek.php";


$nama = $_POST['nama'];

$kelas = $_POST['kelas'];


$input = "insert into pjdua (nama,kelas) values ('$nama','$kelas')";

$hasil=mysqli_query($host, $input);

if ($hasil) {

echo "Proses input data berhasil";

}else{

echo "Proses input data gagal";

}

?>


<?php

require ("konek.php");

$code = mysqli_query($host, "SELECT * FROM pjdua ");


?>


<!DOCTYPE html>

<html>

<head>

<title>Tabel</title>

</head>

<body>

<h2 align="center">ISI</h2>

<table border="5" align="center">

<tr>

<th>No</th>

<th>ID</th>

<th>Nama</th>

<th>Kelas</th>

</tr>

<?php $i = 1; ?>

<?php 

foreach ($code as $row) { ?>


<tr> <td> <?php echo $i; ?></td>

<td> <?php echo $row["id"]; ?></td>

<td> <?php echo $row["nama"]; ?></td>

<td> <?php echo $row["kelas"]; ?></td>

</tr>

<?php $i++; ?>

<?php } ?>

</table>

</body>

</html>








Komentar

Postingan Populer