Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
1.3 kB
3
Indexable
Never
<?php
    require('connect.php');
    
    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
        $postdata = file_get_contents("php://input");
        $request = json_decode($postdata);
    
        if (isset($request->email) && isset($request->accessToken)) {
            $email = $request->email;
    
            $query = "SELECT * FROM tblAccount WHERE email = ?";
            $stmt = mysqli_prepare($con, $query);
            mysqli_stmt_bind_param($stmt, "s", $email);
            mysqli_stmt_execute($stmt);
            mysqli_stmt_store_result($stmt);
            $num_rows = mysqli_stmt_num_rows($stmt);
    
            if ($num_rows > 0) {
                $response = ['success' => true, 'message' => 'Email is registered.'];
            } else {
                // The email is not found in the database
                $response = ['success' => false, 'message' => 'Email is not registered.'];
            }
    
            mysqli_stmt_close($stmt);
        } else {
            $response = ['success' => false, 'message' => 'Invalid request.'];
        }
    
        // Send the JSON response
        header('Content-Type: application/json');
        echo json_encode($response);
    } else {
        echo 'Invalid request method.';
    }
    ?>