<?php
header("Access-Control-Allow-Origin: *");
include 'conexion.php';
$table = 'users';

$getJson = file_get_contents('php://input');
$json = json_decode($getJson);
$userx = $json->userx;
$verifyCode = $json->codex;

$sql = $connect->query("SELECT username, auth_email FROM " . $table . " WHERE username='" . $userx . "' and auth_email='" . $verifyCode . "'");
$cekverify = $sql->num_rows;

$hasil = array();

while ($fetchSql = $sql->fetch_assoc()) {
	$hasil[] = $fetchSql;
}

if ($cekverify > 0) {
	$connect->query("UPDATE " . $table . " SET register_confirmation=1 WHERE username='" . $userx . "' and auth_email='" . $verifyCode . "'");
	$response = array(
		'error' => false,
		'message' => null,
		'data' => $hasil
	);
} else {
	$response = array(
		'error' => true,
		'message' => 'Kode verifikasi Salah',
		'data' => null
	);
}

header('Content-Type: application/json');
echo json_encode($response);
