$hostname_koneksi = "localhost";
$database_koneksi = "ujian_online";
$username_koneksi = "root";
$password_koneksi = "";
$koneksi = mysql_pconnect($hostname_koneksi, $username_koneksi, $password_koneksi) or trigger_error(mysql_error(),E_USER_ERROR);
Selanjutnya saya buat file baru yang berada diluar dari folder "Connections", bernama "simpandata.php". Pada halaman ini saya berikan kode seperti di bawah ini :
<?php
require_once('Connections/koneksi.php');
//---------
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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;
}
}
//-----------
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO tb_paket (kode_paket, nama_paket, limitsoal_paket, guru_paket, ket_paket, ct_paket, cb_paket, active_paket) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['kode_paket'], "text"),
GetSQLValueString($_POST['nama_paket'], "text"),
GetSQLValueString($_POST['limitsoal_paket'], "int"),
GetSQLValueString($_POST['guru_paket'], "int"),
GetSQLValueString($_POST['ket_paket'], "text"),
GetSQLValueString('2020-02-02', "date"),
GetSQLValueString(1, "int"),
GetSQLValueString('Y', "text"));
mysql_select_db($database_koneksi, $koneksi);
$Result1 = mysql_query($insertSQL, $koneksi) or die(mysql_error());
}
?>
Selanjutnya, tepat di bawah penutup tag php, lanjutkan dengan kode form berikut ini
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<table width="100%" height="302">
<tr valign="baseline">
<td width="115" align="right" nowrap="nowrap"><strong>KODE PAKET</strong></td>
<td width="17" align="right" nowrap="nowrap"> </td>
<td width="317"><input type="text" name="kode_paket" value="<?= $kodeacak; ?>" class="form-control input-sm" size="32" required /></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap="nowrap"><strong>NAMA PAKET</strong></td>
<td align="right" nowrap="nowrap"> </td>
<td><input type="text" name="nama_paket" value="" class="form-control input-sm" size="32" required /></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap="nowrap"><strong>LIMIT SOAL</strong></td>
<td align="right" nowrap="nowrap"> </td>
<td><input type="number" name="limitsoal_paket" value="" class="form-control input-sm" size="32" required /></td>
</tr>
<tr valign="baseline">
<td align="right" nowrap="nowrap"><strong>PAKET GURU</strong></td>
<td align="right" nowrap="nowrap"> </td>
<td><input type="text" name="guru_paket" value="" class="form-control input-sm" size="32" required /> </td>
</tr>
<tr valign="baseline">
<td align="right" valign="top" nowrap="nowrap"><strong>KETERANGAN</strong></td>
<td align="right" valign="top" nowrap="nowrap"> </td>
<td><textarea name="ket_paket" cols="50" rows="5" class="form-control input-sm"></textarea> </td>
</tr>
<tr valign="baseline">
<td align="right" nowrap="nowrap"> </td>
<td align="right" nowrap="nowrap"> </td>
<td><input type="submit" value="Simpan Data" class="btn btn-success btn-block" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
Simpan dan jalankan program, Semoga berhasil.