I have this function with quite a simple SQL in it that gives error in the syntax where there couldn't be one.
function createPetition($conn, $pName, $pTarget, $pDescription, $userId) {
    $sql = "INSERT INTO petitions (petitionName, petitionTarget, petitionDescription, usersId) VALUES (?, ?, ?, ?);";
    //$sql2 = "INSERT INTO petitions (`petitionDate`) VALUES (NOW());";
    $stmt = mysqli_stmt_init($conn);
    if (!mysqli_stmt_prepare($stmt, $sql)) {
        header("location: ./index.php?error=stmtfailed");
        exit();
    }
    /*if (!mysqli_stmt_prepare($stmt, $sql2)) {
    header("location: ./index.php?error=stmtdatefailed");
    exit();
    }*/
    
    mysqli_stmt_bind_param($stmt, "ssss", $pName, $pTarget, $pDescription, $userId);
    if (!mysqli_query($conn, $sql)) {
        echo "Error description: " . mysqli_error($conn);
    } else {
        mysqli_stmt_execute($stmt);
        mysqli_stmt_close($stmt);
        header("location: ./petitionfinal.php?error=none");
        exit();
    }
}
The result of which is
Error description: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '?, ?, ?, ?)' at line 1
When there is clearly no error.
 
     
    