Professional Documents
Culture Documents
<?php
$hostname_koneksi = "localhost";
$database_koneksi = "pos";
$username_koneksi = "root";
$password_koneksi = "";
$koneksi = mysqli_connect($hostname_koneksi, $username_koneksi, $password_koneksi) or
trigger_error(mysqli_error($koneksi),E_USER_ERROR);
mysqli_select_db($koneksi, $database_koneksi);
?>
fungsi sanitasi
if (!function_exists("inj")) {
function inj($koneksi, $theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
fungsi kembali
function back() {
echo '<button onclick="window.history.go(-1); return false;"> Go
Back</button>';
}
MENAMPILKAN DATA
$query = "SELECT * FROM table ORDER BY field ASC";
$eksekusi = mysqli_query($koneksi, $query) or
die(errorQuery(mysqli_error($koneksi)));
$row = mysqli_fetch_assoc($eksekusi);
$totalRows = mysqli_num_rows($eksekusi);
EDIT DATA
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
HAPUS DATA
if ((isset($_GET['id'])) && ($_GET['id'] != "")) {