if ($o) {
        $encryptedPassword = $o->password;
    }
    if (strtoupper(md5($password)) == $encryptedPassword) {
        $_SESSION['login'] = true;
        $return = '{"status": "1"}';
        echo $return;
    } else {
        $return = '{"status": ""}';
        echo $return;
    }
}
if (POST('submit') == 'create') {
    $title = POST('title');
    $content = POST('content');
    $statement = savePost2Database($title, $content);
    //echo '{"status": "1", "id": "'.$statement.'","title": "'.$title.'"}';
    echo '{"status": "1", "id": "' . $statement . '"}';
}
if (POST('submit') == 'read') {
    $id = POST('id');
    $statement = getPost($id);
    $post = $statement->fetchObject();
    if ($post) {
        $content = $post->content;
        echo $content;
    } else {
        echo "No post with ID: {$id}";
    }
}
if (POST('submit') == 'update') {
    $statement = savePost2Database($title, $content);
    showModalNotification("Post saved!", "New post has saved with post id: {$statement}");
} elseif (POST('submit') == 'login') {
    $username = $_POST['username'];
    $password = $_POST['password'];
    $statement = getEncryptedPassword($username);
    $encryptedPassword = "";
    $o = $statement->fetchObject();
    if ($o) {
        $encryptedPassword = $o->password;
    }
    if (strtoupper(md5($password)) == $encryptedPassword) {
        $_SESSION['login'] = true;
        //        $title = POST("title");
        //        $content = POST("content");
        //        global $title, $content;
        $statement = savePost2Database($_SESSION['title'], $_SESSION['content']);
        echo "<h3>Login success, saved!</h3>";
        //        showModalNotification("Login succes", "Welcome $username comes back!", "loginSuccess");
        //        showModalNotification("Post saved!", "New post has saved with post id: $statement", "savePostSuccess");
    } else {
        $_SESSION['login'] = false;
        showModalNotification("Login failed", "Please login again");
    }
} else {
    showModalSessionLoginFalse("Action");
    //showModalWhenEdit("myModal");
    ?>

<?php 
}
<?php

//echo "controll create post logic";
if (isset($_POST['submit'])) {
    if ($_POST['submit'] == 'create') {
        $title = $_POST['title'];
        $content = $_POST['content'];
        $_SESSION['id'] = savePost2Database($title, $content);
    }
}