Selasa, 11 Desember 2018
Jumat, 23 Desember 2016
Pelatihan Web Artikel ( CRUD )
23.12.00
Posted by Unknown
- Add.html
<head>
<title>Form Create Data</title>
</head>
<body>
<form method="POST" action="create.php">
<table>
<tr>
<td>Title</td>
<td><input type="text" name="title"></td>
</tr>
<tr>
<td>Content</td>
<td><textarea name="content"></textarea></td>
</tr>
<tr>
<td>Penulis</td>
<td><input type="text" name="penulis"></td>
</tr>
<tr>
<td></td>
<td><button type="submit" value="Add">Create</button></td>
</tr>
</table>
</form>
</body>
</html>
- config.php
<?php
//nama $host bisa diganti sesuai dengan kehendak kita, jika dipakai sendiri
$host = "localhost";
$user = "root";
$pass = "";
$db = "pelatihan2";
$db = "pelatihan2";
$connect = mysqli_connect($host, $user, $pass) or die ("connection failed!");
mysqli_select_db($connect,$db) or die ("database not found!");
?>
- create.php
<?php
include 'config.php';
$title = $_POST['title'];
$content = $_POST['content'];
$penulis = $_POST['penulis'];
$result = mysqli_query($connect, "INSERT INTO articles(title,content,penulis) VALUES('$title', '$content', '$penulis')");
if ($result){
header('location:index.php');
} else {
mysqli_error();
}
?>
- delete.php
<?php
include 'config.php';
$id = $_GET['id'];
$result = mysqli_query($connect, "DELETE FROM articles WHERE id=$id");
if($result){
header('location:index.php');
} else{
echo "Error";
}
?>
- edit.php
<?php
include 'config.php';
$id = $_GET['id'];
$result = mysqli_query($connect, "SELECT * FROM articles WHERE id=$id");
$data = mysqli_fetch_assoc($result);
?>
<html>
<head>
<title>Edit Data</title>
</head>
<body>
<form method="POST" action="update.php">
<table>
<tr>
<td>Title</td>
<td><input type="text" value="<?php echo $data['title']; ?>" name="title"></td>
</tr>
<tr>
<td>Content</td>
<td><textarea name="content"><?php echo $data['content']; ?></textarea></td>
</tr>
<tr>
<td>Penulis</td>
<td><input type="text" value="<?php echo $data['penulis']; ?>" name="penulis"></td>
</tr>
<tr>
<td><input type="hidden" name="id" value="<?php echo $id ?>"></td>
<td><button type="submit" value="update">Update</button></td>
</tr>
</table>
</form>
</body>
</html>
- index.php
<?php
include 'config.php';
$result = mysqli_query($connect, "SELECT * FROM articles");
?>
<html>
<head>
<title></title>
</head>
<body>
<table>
<tr>
<td>No</td>
<td>Title</td>
<td>Content</td>
<td>Penulis</td>
<td>Action</td>
</tr>
<?php
$no = 1;
while ($data = mysqli_fetch_assoc($result)){
echo "<tr>";
echo "<td>".$no."</td>";
echo "<td>".$data['title']."</td>";
echo "<td>".$data['content']."</td>";
echo "<td>".$data['penulis']."</td>";
echo "<td>
<a href=\"edit.php?id=$data[id]\">Edit</a> |
<a href=\"delete.php?id=$data[id]\"onClick=\"return confirm('Are u Sure?')\">Delete</a></td>";
echo "</tr>";
$no++;
}
?>
</table>
</body>
</html>
- update.php
<?php
include 'config.php';
$id= $_POST['id'];
$title= $_POST['title'];
$content= $_POST['content'];
$penulis= $_POST['penulis'];
$update = mysqli_query($connect, "UPDATE articles SET title='$title', content='$content', penulis='$penulis' WHERE id='$id'");
if($update){
header('location:index.php');
}
else{
echo "Error";
}
?>
Kamis, 22 September 2016
Tugas Pemrograman Web Dinamis ( Tugas 2 )
Biodata Teman ( Tugas 2 )
- Index.php
session_start();
$_SESSION['ZAKY']=0;
header("location;tugaspwd2.php")
?>
- tugaspwd2.php
<head>
<title>Tugas Pemrograman Web Dinamis 2</title>
</head>
<body>
<hr></hr><br><center><b>Biodata Teman</b></center><br><hr></hr></br>
<form action="tugaspwd2.php" method="post">
<pre>
<center>Masukan Nama : <input type="text" name="RATNA" value=""></center>
<center>Masukan Alamat : <input type="text" name="VITRIA" value=""></center>
<center>     <input type="submit" value="Input"></center><br><hr></hr>
</pre>
</form>
<table>
<pre>
<tr><td>Nama</td><td>Alamat</td></tr>
</pre>
<?php
session_start();
if(isset($_POST['RATNA'])){
$_SESSION['RATNA'][$_SESSION['ZAKY']]=$_POST['RATNA'];
$_SESSION['VITRIA'][$_SESSION['ZAKY']]=$_POST['VITRIA'];
$_SESSION['ZAKY']++;
}
for($i=0;$i<$_SESSION['ZAKY'];$i++){
echo "<tr><td>".$_SESSION['RATNA'][$i]."</td>";
echo "<td>".$_SESSION['VITRIA'][$i]."</td></tr>";
}
?>
</table>
- Output Program
- index.php
- tugaspwd2.php
- tugaspwd2.php (input pertama)
- tugaspwd2.php (input kedua)
Langganan:
Postingan (Atom)
Entri
-
Kriptografi (cryptography) Kriptografi (cryptography) merupakan ilmu dan seni untuk menjaga pesan agar aman. Kriptografi (Cryptograp...
-
#include <iostream> #include <ctime> #include <windows.h> #define BARIS 5 #define KOLOM 5 #define SPASI 32 #d...
-
Biodata Teman ( Tugas 2 ) Index.php <?php session_start(); $_SESSION['ZAKY']=0; header("location;tugaspwd2.php...
-
Program Menghitung_2_ Buah_Pecahan_Dengan _4_ operator { Dibaca 2 buah pecahan P1 dan P2, hitunglah jumlah 2 pecahan, pengurangan, perkal...
-
BIODATA TEMAN (PHP) Cara Pertama <?php $nama1 = "Satrio Mukti W"; $nama2 = "Muhammad Jubaidi"; $...
-
#include <cstdlib> #include <iostream> using namespace std; int main(int argc, char *argv[]) {double x,y,z; cout<...
-
KOMUNIKASI ORGANISASI A. Pengertian Komunikasi Organisasi Komunikasi organisasi adalah pengiriman dan penerimaan...
-
#include <cstdlib> #include <iostream> using namespace std; int main(int argc, char *argv[]) { int nilai; cout<...