Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //nama file : simpan_registrasi.php
- require("config.php");
- require("config_database.php");
- if(isset($_POST['submit'])){
- $username = $_POST['username'];
- //OPTIONAl
- $username = trim($username); // menghilangkan spasi didepna dan dibelakang teks
- $username = strip_tags($username); //membuat tag html pada teks
- /* SILAKAN PELAJAROI FUNGSI htmlspecialchars, htmlspecialchars_decode,htmlentities, html_entity_decode */
- $password1 = $_POST['password'];
- $password2 = $_POST['password'];
- if($password1 != $password2){
- //password tidak sama
- echo "Password yang anda masukkan tidak sama!";
- echo "<br/><a href=''> Coba Lagi</a>";
- } else {
- //HASH PASSWORD
- $password = md5($password1); //md5
- //$password = sha1($password1); //sha1
- //query sql INSERT
- $sql = "INSERT INTO users (username, password) values('".$username."', '"$password."')";
- //jalankan query INSERT
- $result = mysqli_query($conn, $sql);
- if($result){
- echo "Data USER berhasil disimpan, <a href=''>lihat data<a/>";
- } else {
- echo "Data USER gagal disimpan, <a href=''>Coba Lagi</a>";
- echo "<br/>";
- echo ("Error description: ". mysqli_error)$conn));
- }
- }
- }else {
- //kembalikan lagi kehalaman register / users(redirect)
- header('Location: '.BASE_URL.'/register.php');
- }
- ?>
Add Comment
Please, Sign In to add comment