Вы находитесь на странице: 1из 3

<?php require_once('Connections/koneksi.php'); ?

>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDe
finedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_st
ring($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"))
{
isset($_POST["rek"]);
$rek=$_POST['rek'];
mysql_select_db($database_koneksi, $koneksi);
$cekdata="SELECT rek FROM nasabah WHERE rek='$rek'";
$duplikat=mysql_query($cekdata) or die (mysql_error());
if(mysql_num_rows($duplikat)>0)
{
echo "<h3>REKENING TELAH TERDAFTAR!</h3>";
}
else
{
$insertSQL = sprintf("INSERT INTO nasabah (rek, nama, em
ail, password) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST['rek'], "int"),
GetSQLValueString($_POST['nama'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['password'], "text"));
mysql_select_db($database_koneksi, $koneksi);
$Result1 = mysql_query($insertSQL, $koneksi) or die(mysql_error());
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or
g/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<script language="javascript">
function hanyaAngka(e, decimal) {
var key;
var keychar;
if (window.event) {
key = window.event.keyCode;
} else
if (e) {
key = e.which;
} else return true;

keychar = String.fromCharCode(key);
if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==2
7) ) {
return true;
} else
if ((("0123456789").indexOf(keychar) > -1)) {
return true;
} else
if (decimal && (keychar == ".")) {
return true;
} else return false;
}
</script>
<body>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="for
m1">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">Rek:</td>
<td><input type="text" name="rek" onkeypress="return hanyaAngka(event, fal
se)" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Nama:</td>
<td><input type="text" name="nama" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Email:</td>
<td><input type="text" name="email" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Password:</td>
<td><input type="text" name="password" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">&nbsp;</td>
<td><input type="submit" value="Insert record" name="simpan"/></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
<?php
//Konfigurasi koneksi server
$namaserver ="localhost";
$namauser="root";
$passuser="";
$koneksi = mysql_connect($namaserver,$namauser,$passuser);
if (!$koneksi)
{
die('<h1>Gagal melakukan koneksi karena : ' . mysql_error()."</h1>");
}
// Proses membuat tabel
mysql_select_db('latihan', $koneksi);
if(isset($_POST)){
if(isset($_POST["rek"])){
$rek=$_POST['rek'];
$buat_tabel = "CREATE TABLE `$rek` (`nim` CHAR(12) NOT NULL, `na
ma` VARCHAR(50) NOT NULL, `tempat_lahir` VARCHAR(30) NOT NULL, `tanggal_lahir` D
ATE NOT NULL) ENGINE = InnoDB;";
mysql_query($buat_tabel,$koneksi);
mysql_close($koneksi);
exit();
}
}
?>
</body>
</html>