Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // START: File connection.php ==============================================
- <?php
- class Connections {
- var $conn;
- private $db_host = 'localhost';
- private $db_user = 'root';
- private $db_pswd = '';
- private $db_name = 'lat_crud';
- public function OpenConnection() {
- $this->conn = new mysqli( $this->db_host, $this->db_user, $this->db_pswd, $this->db_name );
- if ( $this->conn->connect_errno ) {
- die ( "Connection problem !". $this->conn->connect_error );
- }
- // return $this->conn;
- }
- public function CloseConnection() {
- $this->conn->close();
- }
- } // END: Class Connections
- // END: File connection.php ==================================================
- // START: File data-diri.php =========================================================
- <?php
- include "Connection.php";
- class DataDiri {
- private $c, $nama, $email, $telp, $username, $password;
- private $insert;
- public function getNama() {
- return $this->nama;
- }
- public function setNama( $nama ) {
- $this->nama = $nama;
- }
- public function getEmail() {
- return $this->email;
- }
- public function setEmail( $email ) {
- return $this->email = $email;
- }
- public function getTelp() {
- return $this->telp;
- }
- public function setTelp( $telp ) {
- $this->telp = $telp;
- }
- public function getUsername() {
- return $this->username;
- }
- public function setUsername( $username ) {
- $this->username = $username;
- }
- public function getPassword() {
- return $this->password;
- }
- public function setPassword( $password ) {
- return $this->password = $password;
- }
- public function getInsert() {
- $insert = false;
- $sql = "INSERT INTO data_diri( nama, email, telp, username, password )
- VALUES ( '". $this->getNama() ."',
- '". $this->getEmail() ."',
- '". $this->getTelp() ."',
- '". $this->getUsername() ."',
- '". md5( $this->getPassword() ) ."'
- )";
- $c = new Connections();
- $c->OpenConnection();
- $query = $this->conn->query( $sql ) or die ( $this->conn->error );
- if ( $query ) {
- $insert = true;
- return $insert;
- $c->CloseConnection();
- }
- }
- } // END: Class DataDiri
- // ================
- $nama = $_POST['nama'];
- $email = $_POST['email'];
- $telp = $_POST['telp'];
- $username = $_POST['username'];
- $password = $_POST['password'];
- $dt = new DataDiri();
- $dt->setNama( $nama );
- $dt->setEmail( $email );
- $dt->setTelp( $telp );
- $dt->setUsername( $username );
- $dt->setPassword( $password );
- $hasil = $dt->getInsert();
- if ( $hasil ) {
- echo "<script>alert( 'Data berhasil disimpan !' ); window.location.href='./';</script>";
- } else {
- die( 'Gagal tersimpan'. $this->conn->error );
- }
- // END: File data-diri.php ==================================================
- // START: File index.php ==================================================
- <form action="data-diri.php" method="post">
- <table>
- <tr>
- <td></td>
- <td></td>
- <td><input type="text" name="nama" placeholder="Nama"></td>
- </tr>
- <tr>
- <td></td>
- <td></td>
- <td><input type="email" name="email" placeholder="Email"></td>
- </tr>
- <tr>
- <td></td>
- <td></td>
- <td><input type="text" name="telp" placeholder="No Telp"></td>
- </tr>
- <tr>
- <td></td>
- <td></td>
- <td><input type="text" name="username" placeholder="Username"></td>
- </tr>
- <tr>
- <td></td>
- <td></td>
- <td><input type="password" name="password" placeholder="Password"></td>
- </tr>
- <tr>
- <td></td>
- <td></td>
- <td><input type="submit" name="submit-btn"></td>
- </tr>
- </table>
- </form>
- // END: File index.php ==================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement