<?php 
require_once 'connect.php';
if( isset($_POST['username']) && isset($_POST['password']) ){

	$username = $_POST['username'];
	$password = $_POST['password'];

	if( !empty($username) && !empty($password) ){
		$checker =$wpdb->get_results("SELECT * FROM formdatabase_users WHERE user_name='".$username."'");
		if( !empty($checker) ) {
			echo "User already exists.";
			exit;
		}else{
			$data = array(
				'user_name' => $_POST['username'],
				'user_pass' => $_POST['password']
				);
			$insert = $wpdb->insert('formdatabase_users',$data);
			if($insert == TRUE){
				unset($_POST);
				echo "success";
			}else{
				echo "failed";
			}
			// $sql = "INSERT INTO formdatabase_users (user_name,user_pass) VALUES ('".$username."','".$password."')";
			// if($conn->query($sql) == TRUE){
			// 	unset($_POST);
			// 	echo "success";
			// }
			// else{
			// 	echo "failed";
			// }
		}
		
	}
}
?>