SQLite PDO - Data not inserted to database

时间:2019-01-15 18:23:19

标签: php sqlite

sorry for my bad english, im new in php.

so I have a game server, I want to make players register through the website and save the data via the Accounts.db file

my database configuration

try {
    # SQLite Database
    $dbh = new PDO("sqlite:/home/samp/scriptfiles/Accounts.db");
}
catch(PDOException $e) {
    echo $e->getMessage();
}

my php file

$error = '';
$success = '';

if (isset($_POST['submit'])){
    global $dbh;

    $username = $_POST['username'];
    $password = $_POST['password'];
    $cpassword = $_POST['cpassword'];
    $hashed = num_hash($password);
    $checkusername = strpos($username, "_");
    $sql = "SELECT COUNT(*) FROM `Accounts` WHERE `Username` = '$username'";
    $checkexist = $dbh->query($sql);

    if (!empty(trim($username)) && (!empty(trim($password)))){
        //$recaptcha_secret = "6LcM1EYUAAAAAF1cINK71jkpRfoqlGec58r8bIkf";
        //$response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$recaptcha_secret."&response=".$_POST['g-recaptcha-response']);
        //$response = json_decode($response, true);
        //if($response["success"] === true) {
            if ($checkusername) {
                if ($password == $cpassword){
                    if ($checkexist->fetchColumn() == 0) {
                        $sql = "INSERT INTO `Accounts` (`Username`, `Password`) VALUES(?, ?)";
                        $insert->execute(array($username, $hashed));
                        if ($insert) {
                            $success = 'Berhasil melakukan registrasi.';
                        } else {
                            $error = 'Database error.';
                        }
                    } else {
                        $error =  'Username sudah digunakan.';
                    }
                } else {
                    $error =  'Password yang anda masukan tidak sama.';
                }
            } else {
                $error = 'Username akan digunakan sebagai Nama Karakter, gunakan format NamaDepan_NamaBelakang. Contoh: John_Smith';
            }
        //} else {
        //  $error= 'Apakah anda robot? Silahkan selesaikan captcha sebelum login';
        //}
    } else {
        $error = 'You should input Username & Password!';
    }
}

when I try to register on the website, it gives a successful notification but the data is not entered into the Accounts.db file. you can try it on my website

Thanks for your help

0 个答案:

没有答案