Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //koneksi database
- $dbhost = 'localhost';
- $dbuser = 'root';
- $dbpass = '';
- $dbname = 'smartphone';
- $conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
- function nilai($query) {
- global $conn;
- $result = mysqli_query($conn, $query);
- $rows = [];
- while($row = mysqli_fetch_assoc($result)) {
- $rows [] = $row;
- }
- return $rows;
- }
- function kirim($insert) {
- global $conn;
- $brand = htmlspecialchars($insert['brand'], ENT_QUOTES);
- $product = htmlspecialchars($insert['product'], ENT_QUOTES);
- $date_realise = htmlspecialchars($insert['date_realise'], ENT_QUOTES);
- $price = htmlspecialchars($insert['price'], ENT_QUOTES);
- $image = htmlspecialchars($insert['image'], ENT_QUOTES);
- $query = "INSERT INTO android (
- brand,
- product,
- date_realise,
- price,
- image )
- VALUES (
- '$brand',
- '$product',
- '$date_realise',
- '$price',
- '$image'
- )";
- $result = mysqli_query($conn, $query);
- }
- function cari($search) {
- global $conn;
- $result = mysqli_query($conn, $search);
- $rows = [];
- while($row = mysqli_fetch_assoc($result)) :
- $rows [] = $row;
- endwhile;
- return $rows;
- }
- function hapus($del_id) {
- global $conn;
- $delete = "DELETE FROM android WHERE id = '$del_id' ";
- $result = mysqli_query($conn, $delete);
- }
- function ubah($update_id) {
- global $conn;
- $id = $update_id['id'];
- $brand = htmlspecialchars($update_id['brand']);
- $product = htmlspecialchars($update_id['product']);
- $date_realise = htmlspecialchars($update_id['date_realise']);
- $price = htmlspecialchars($update_id['price']);
- $image = htmlspecialchars($update_id['image']);
- $update = "UPDATE android SET
- brand = '$brand',
- product = '$product',
- date_realise = '$date_realise',
- price = '$price',
- image = '$image'
- WHERE id = '$id' ";
- $result = mysqli_query($conn, $update);
- }
- ?>
Add Comment
Please, Sign In to add comment