<?php
session_start();

$chap = $_SESSION['inactive'];
include "../../connect/db.php";

// Create a new MySQLi instance
$mysqli = new mysqli($host, $username, $password, $dbname);

// Check connection
if ($mysqli->connect_error) {
    echo "error";
    exit();
}

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $occupation = $mysqli->real_escape_string($_POST['occupation']);
    $income = $mysqli->real_escape_string($_POST['income']);
    $next_kin = $mysqli->real_escape_string($_POST['next_kin']);
    $next_address = $mysqli->real_escape_string($_POST['next_address']);
    $next_relationship = $mysqli->real_escape_string($_POST['next_relationship']);
    $password = $mysqli->real_escape_string($_POST['password']);
    $secretCode = $mysqli->real_escape_string($_POST['secretCode']);
    $securityquestion = $mysqli->real_escape_string($_POST['securityquestion']);
    $answer = $mysqli->real_escape_string($_POST['answer']);
    $securityquestion2 = $mysqli->real_escape_string($_POST['securityquestion2']);
    $answer2 = $mysqli->real_escape_string($_POST['answer2']);

    $sql = "UPDATE users 
            SET occupation = '$occupation',
                income = '$income',
                next_kin = '$next_kin',
                next_address = '$next_address',
                next_relationship = '$next_relationship',
                password = '$password',
                secretCode = '$secretCode',
                securityquestion = '$securityquestion',
                answer = '$answer',
                securityquestion2 = '$securityquestion2',
                answer2 = '$answer2',
                reg_step = 'step2'
            WHERE email = '$chap'";

    if ($mysqli->query($sql) === TRUE) {
        echo "success";
    } else {
        echo "error";
    }

    $mysqli->close();
}
?>
