Skip to content

Instantly share code, notes, and snippets.

@wichaksono
Created October 19, 2016 10:51
Show Gist options
  • Save wichaksono/12f1e92011abef71fd5427c0411ee3e1 to your computer and use it in GitHub Desktop.
Save wichaksono/12f1e92011abef71fd5427c0411ee3e1 to your computer and use it in GitHub Desktop.
<?php
if (isset($_POST['nickname']) && $_POST['nickname']) {
// memasukan file koneksi ke database
require_once 'config.php';
// menyimpan variable yang dikirim Form
$nama = $_POST['nickname'];
$username = $_POST['username'];
$password = $_POST['password'];
$repassword = $_POST['repassword'];
// cek nilai variable
if (empty($nama)) {
header('location: ./register.php?error=' .base64_encode('Nama tidak boleh kosong'));
}
if (empty($username)) {
header('location: ./register.php?error=' .base64_encode('Username tidak boleh kosong'));
}
if (empty($password)) {
header('location: ./register.php?error=' .base64_encode('Password tidak boleh kosong'));
}
// validasi apakah password dengan repassword sama
if ($password != $repassword) { // jika tidak sama
header('location: ./register.php?error=' .base64_encode('Password tidak boleh sama'));
}
// encryption dengan md5
$password = md5($password);
$level = 'member'; // default,
// SQL Insert
$sql = "INSERT INTO users (nama, username, password, level_user) VALUES ('$nama', '$username', '$password', '$level')";
$insert = $dbconnect->query($sql);
// jika gagal
if (! $insert) {
echo "<script>alert('".$dbconnect->error."'); window.location.href = './register.php';</script>";
} else {
echo "<script>alert('Insert Data Berhasil'); window.location.href = './login.php';</script>";
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment