prepare("select username from accounts where username=?;"); $stmt->bindValue(1, $form_username, SQLITE3_TEXT); //max length 256 $result = $stmt->execute(); if ( $result->fetchArray() && $result->fetchArray()[0] != null ) { die('user exists - click back'); } else { //INSERT USER IN DATABASE //HASH Password $hashed_password = password_hash($form_userpassword, PASSWORD_DEFAULT); $qry_insert = $db->prepare( 'INSERT INTO accounts (username, userpassword) VALUES (?,?)'); $qry_insert->bindValue(1, $form_username, SQLITE3_TEXT); $qry_insert->bindValue(2, $hashed_password, SQLITE3_TEXT); $res = $qry_insert->execute(); $lastInsertId = $db->lastInsertRowID(); my_session_regenerate_id(); $_SESSION['user_id'] = $lastInsertId; } //Redirect to a different page in the current directory that was requested $host = $_SERVER['HTTP_HOST']; $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); $extra = 'index.php'; //header location will automatically kill the code below it header("Location: http://$host$uri/$extra"); ob_end_flush(); ?>