<?php 
require_once '../config/db.php';
require_once '../config/database.class.php';
require_once '../config/functions.php';
$d = new database($db_config);


if(isset($_POST)){
	$post  =$_POST;
	$username = $post['username'];
	$email= $post['email'];
	$password= $post['password'];

	if($post['id']==''){
    $query = "INSERT INTO register(`username`,`email`,`password`) VALUES('$username','$email','$password')";
        $executeQuery = $d->insertQuery($query);
        if($executeQuery){
        	echo getResponse('success','Data saved successfully');
        	?>
        	 <script >
 alert('Registered successfully! Please login');
	 document.location.href = "../view/login.php"
   
    </script><?php
        }else{
        	echo getResponse('error','Something went wrong, please try later!');
        }
	}else{
$id = $post['id'];
		$query = "UPDATE register SET username='".$username."', email='".$email."',password='".$password."' WHERE id=$id";
        $executeQuery = $d->updateQuery($query);
        if($executeQuery){
        	echo getResponse('success','Data updated successfully');
        }else{
        	echo getResponse('error','Something went wrong, please try later!');
        }

	}
}
?>