Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ** percobaan pake db login
- ** tinggal penyesuaian aja
- **
- */
- <?php
- if (isset($_POST['btn-simpan'])) {
- $link = new mysqli('localhost', 'root', 'R0ckmyta', 'tutorial');
- if ($link->connect_errno) {
- echo "Can't Connect to Database : " . $link->connect_error;
- }
- $email = strip_tags(trim($_POST['email']));
- $user = strip_tags(trim($_POST['nama']));
- $pass = strip_tags(trim($_POST['noreg']));
- // SQL Injection
- $mail = $link->real_escape_string($email);
- $username=$link->real_escape_string($user);
- $password=$link->real_escape_string($pass);
- // Cek Data
- $stmt = $link->prepare("SELECT * FROM login WHERE email = ? OR username = ?");
- $stmt->bind_param("ss", $email, $username);
- $stmt->execute();
- // Ambil hasil query
- $result = $stmt->get_result();
- // Cek email sudah pernah tersimpan di db / belum?
- if ($result->num_rows > 0) {
- echo "Sorry, username already exists";
- } else {
- // Insert Data
- $insert = $link->prepare("INSERT INTO login (email, username, password) VALUES (?, ?, ?)");
- $insert->bind_param("sss", $mail, $username, $password);
- $insert->execute();
- if ($insert) {
- echo "Success";
- header("Location: index.php");
- }
- }
- } /* end isset */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement