Skip to content

Instantly share code, notes, and snippets.

@uluumbch
Created April 11, 2022 04:35
Show Gist options
  • Save uluumbch/ad29af74935f77cf9bc863a75b23bb36 to your computer and use it in GitHub Desktop.
Save uluumbch/ad29af74935f77cf9bc863a75b23bb36 to your computer and use it in GitHub Desktop.
Jawaban UTS Pemrograman Web II Semester Genap Teknologi Informasi Universitas Lambung Mangkurat
<!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">
<title>soal 1</title>
</head>
<body>
<form action="" method="post">
<input type="text" name="angka">
<input type="submit" value="submit" name="submit">
</form>
<ul>
<?php
if (isset($_POST['submit'])) {
for ($i = 1; $i <= $_POST['angka']; $i++) {
echo "<li>$i</li>";
}
}
?>
</ul>
</body>
</html>
<!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">
<title>soal 2</title>
</head>
<body>
<form action="2respons.php" method="post">
jumlah baris: <br>
<input type="text" name="baris"> <br>
jumlah kolom: <br>
<input type="text" name="kolom"> <br>
<input type="submit" value="Buat tabel">
</form>
</body>
</html>
<!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">
<title>hasil tabel</title>
</head>
<body>
<?php
$baris = $_POST['baris'];
$kolom = $_POST['kolom'];
if (empty($baris) && empty($kolom)) {
echo "<h1>Anda belum memasukkan jumlah baris dan kolom</h1>";
} else if (empty($kolom)) {
echo "<h1>Anda belum memasukkan jumlah kolom</h1>";
} else if (empty($baris)) {
echo "<h1>Anda belum memasukkan jumlah baris</h1>";
} else {
echo "<table border= \"1\" style=\"width: 200px; height: 200px\" ";
for ($jumlahBaris = 0; $jumlahBaris < $baris; $jumlahBaris++) {
echo "<tr>";
for ($jumlahKolom = 0; $jumlahKolom < $kolom; $jumlahKolom++) {
echo "<td> </td>";
}
echo "</tr>";
}
echo "</table>";
}
?>
</body>
</html>
<!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">
<title>soal 3</title>
</head>
<body>
<form action="" method="post">
Pilih Ukuran : <br>
<select name="ukuran">
<option <?php if (isset($_POST['submit']) && $_POST['ukuran'] == 'kecil') {
echo "selected";
} ?> value="kecil">kecil</option>
<option <?php if (isset($_POST['submit']) && $_POST['ukuran'] == 'sedang') {
echo "selected";
} ?> value="sedang">sedang</option>
<option <?php if (isset($_POST['submit']) && $_POST['ukuran'] == 'besar') {
echo "selected";
} ?> value="besar">besar</option>
<input type="submit" value="pilih" name="submit">
</select>
</form>
<?php
if (isset($_POST['submit'])) {
$ukuran = $_POST['ukuran'];
switch ($ukuran) {
case 'kecil':
echo "<div style=\" width: 50px; height: 50px; border: 1px solid #000\" ";
break;
case 'sedang':
echo "<div style=\" width: 150px; height: 150px; border: 1px solid #000\" ";
break;
case 'besar':
echo "<div style=\" width: 300px; height: 300px; border: 1px solid #000\" ";
break;
}
}
?>
</body>
</html>
<!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">
<title>soal 4</title>
</head>
<body>
<form action="4respon.php" method="post">
username : <br>
<input type="text" name="username"> <br>
password: <br>
<input type="password" name="password"> <br>
<input type="submit" value="login" name="submit">
</form>
</body>
</html>
<!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">
<title>halaman login</title>
</head>
<body>
<?php
$data = ["username" => "uluumbch", "password" => "12345"];
if (isset($_POST['submit'])) {
if ($_POST['username'] == $data['username'] && $_POST['password'] == $data['password']) {
echo "<h1>Selamat datang Admin</h1>";
} else {
echo "<h1>Maaf username atau password yang anda masukkan salah</h1>";
}
}
?>
</body>
</html>
<!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">
<title>soal 5</title>
</head>
<body>
<form action="" method="post">
Masukkan jumlah baris : <input type="number" name="baris"> <br>
Masukkan jumlah kolom : <input type="number" name="kolom"> <br>
<input type="submit" value="submit" name="submit">
</form>
<?php
if (isset($_POST['submit'])) {
$baris = $_POST['baris'];
$kolom = $_POST['kolom'];
echo "<table border=\"1\" style=\"width: 100px; height: 100px;\">";
for ($jumlahBaris = 1; $jumlahBaris <= $baris; $jumlahBaris++) {
echo "<tr>";
for ($jumlahKolom = 1; $jumlahKolom <= $kolom; $jumlahKolom++) {
if ($jumlahBaris == 1) {
echo "<td> $jumlahKolom </td>";
} else if ($jumlahKolom == 1) {
echo "<td> $jumlahBaris </td>";
} else {
echo "<td>" . $jumlahKolom + $jumlahBaris . "</td>";
}
}
echo "</tr>";
}
echo "</table>";
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment